Adding new HighChart Series

让人想犯罪 __ 提交于 2019-11-29 14:41:21

问题


At this code javascrip give an error

$.each(JSON, function(i, array) {                        
    chart.series[i].name = array.teamName;
    chart.series[i].setData(array.teamPower, true);
});

I must define the chart.series[i] because it say "Cannot set property 'name' of undefined" but i can't find a way in order to do this.

Because it fonction runs with requestData so it came after chart determine with options

function showGraph() {  
    chart = new Highcharts.Chart(option);       
}

chart: {
    renderTo: 'graphicShow',
    type: 'spline',
    events: {
        load: requestData
    }
}

...in option...

title: {
    text: 'Power %'
},
series: []

...


回答1:


You need to looka at the "Methods and Properties" part of the API. See http://api.highcharts.com/highcharts#Chart (There is an jsFiddle on the documentation page as well).

var chart = new Highcharts.Chart(options);
chart.addSeries({                        
    name: array.teamName,
    data: array.teamPowher
});

If you are going to add several series you should set the redraw flag to false and then call redraw manually after as that will be much faster.

var chart = new Highcharts.Chart(options);
chart.addSeries({                        
    name: array.teamName,
    data: array.teamPower
}, false);
chart.addSeries({                        
    name: array.teamName,
    data: array.teamPower
}, false);
chart.redraw();



回答2:


You too can specify as second option of addSeries a boolean value, that indicates if it redraws or not



来源:https://stackoverflow.com/questions/14166561/adding-new-highchart-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!