Accepted answer

I solved the problem

Changed json array as follows:

var sales = [ 
              { "name"  : "AllProducts123|Canada", "data" :[44936.0,50752.0] },
              { "name"  : "AllProducts|Mexico", "data" : [200679.0,226838.0] },
              { "name"  : "AllProducts|USA",    "data" : [288993.0,289126.0] }

Now pass it directly to series in highcharts.


Done !!!!!


Instead of constructing the series array manually you could loop through the sales variable data and construct the array. So what ever the number of elements in the sales.SalesData array, all items will be there in the series array

var series = [],
    salesData= sales.SalesData;

for (var i=0 i< salesData.length; i++) {
    series.push({"name" : key, "data" : sales[key]})

This constructed series array is part of the object which you must pass as argument to highcharts method.

var chartdata = {
    chart: {type: 'column'},
    title: {text: 'Sales Data'},
    xAxis: {
        categories: ['Category 1','Category 2']
    yAxis: {
        min: 0,
        title: {text: 'Sales'}
    series : []

chartdata.series = series;


where #chart is the container where you want to display the chart.

you can also refer to the fiddles which are available in their demo pages for each type of chart to know more on how to display a particular type of chart.

Related Query

More Query from same tag