Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

arrays - Adding new HighChart Series

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: []

...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...