Kamran
Kamran

Reputation: 4100

Highchart Json Format for Highchart stock chart

From the examples given by highcharts the Json format for highStock is:

[
[1237766400000,174.13],
[1237852800000,173.41],
[1237939200000,171.86],
[1238025600000,176.47],
[1238112000000,173.68],
[1238371200000,171.17],
[1238457600000,173.86]
]

But I want to put the name of the series inside the Json data as:

[
    {"name":"USD"},
     {"data":
      [
        [1237766400000,174.13],
        [1237852800000,173.41],
        [1237939200000,171.86],
        [1238025600000,176.47],
        [1238112000000,173.68],
        [1238371200000,171.17],
        [1238457600000,173.86]
      ]
     }
]

Here is my Code:

var  currCodeArray = ['USD']

$.each(currCodeArray, function(i, currCode) {

        $.getJSON('//servername/GetHighChartData.ashx?currCode='+currCode, function(data) {
            createChart(data);
         });
    });

    function createChart(data) {

      $('#container').highcharts('StockChart', {

          yAxis: {
            opposite: false,
            labels: {
              format: '{value:.2f}'
            }

          },

          legend: {
            enabled: true
          },
          series: data

        });
      }

Problem is I see the chart as:

enter image description here

Upvotes: 0

Views: 470

Answers (1)

Rahul Sharma
Rahul Sharma

Reputation: 912

Sending data in

[
{"name":"USD"},
 {"data":
  [
    [1237766400000,174.13],
    [1237852800000,173.41],
    [1237939200000,171.86],
    [1238025600000,176.47],
    [1238112000000,173.68],
    [1238371200000,171.17],
    [1238457600000,173.86]
  ]
 }
]

format basically means you are sending data for two different series, since there are two objects in the array. Change it to

[
{"name":"USD",
 "data":
  [
    [1237766400000,174.13],
    [1237852800000,173.41],
    [1237939200000,171.86],
    [1238025600000,176.47],
    [1238112000000,173.68],
    [1238371200000,171.17],
    [1238457600000,173.86]
  ]
 }
]

Notice that I have removed the curly brackets after "USD" and before "data".

Upvotes: 3

Related Questions