添加新的 HighChart 系列 [英] Adding new HighChart Series

查看:22
本文介绍了添加新的 HighChart 系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中,javascrip 给出了一个错误

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

我必须定义 chart.series[i] 因为它说无法设置未定义的属性'名称'"但我找不到方法来做到这一点.

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.

因为它的功能与 requestData 一起运行,所以它是在图表确定与选项之后出现的

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

...

推荐答案

您需要查看 API 的方法和属性"部分.参见 http://api.highcharts.com/highcharts#Chart(上面有一个 jsFiddle文档页面也是如此).

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

如果您要添加多个系列,您应该将 redraw 标志设置为 false,然后手动调用重绘,因为这样会快得多.

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

这篇关于添加新的 HighChart 系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆