score:1

Accepted answer

I think you are trying to do something what you already have done.

You want to get display three series from your JSON, for respective categories, then let's to that:

Your code:

var categories = testDia['chartCategories'];
var series = testDia['chartSeries'];

Great! Now use that variables:

newChart = new Highcharts.Chart({
    chart : {
        renderTo : portletContainer,
        type: 'column'
    },
    ...
    xAxis: {
        categories: categories,
        labels: {
            rotation: -45,
            align: 'right',
        }
    },
    ...
    series: [{
        name: 'Positive',
        data: series.positive // testDia.chartSeries.positive is the same
    }, {
        name: 'Neutral',
        data: series.neutral
    }, {
        name: 'Negative',
        data: series.negative
    }]
});

And working demo: http://jsfiddle.net/x8455/1/

score:1

Here's how you should do it.

var allPositiveData = []; // You want an array, so start off with an array.

for(var i=0; i < categories.length; i++) {
    var diaPositive = series['positive'][i]['y'];
    urlPositive = series['positive'][i]['url'];
    allPositiveData.push({'y':diaPositive, 'url':urlPositive}); // Add the element to the array.
}

That's all there is to it. Your Highcharts-setup piece of code can remain the same.

To make the sample a little shorter, I only edited the code for the positive data, the rest is the same, just a different name.


Related Articles