我想在配置highchart-code之前操作var系列。
但我得到68系列!而不是我之前定义的2系列。
错误是什么?
var series;
function refresher() {
series = "[{ name = 'test1', data = data[0]},{ name = 'test', data = data[1]}]";
$.getJSON(url,
function(data) {
chart = new Highcharts.StockChart
({
chart: { renderTo: 'container', zoomType: 'x', type: 'line', width: 900 },
legend: { enabled: true, verticalAlign:'bottom' },
title: { text: 'You see the data of the last measured hour!' },
credits: { enabled: false },
xAxis: { type: 'datetime', title: { text: 'time' } },
yAxis: { title: { text: 'hallo' } },
rangeSelector:{ enabled: false },
navigator : { enabled: false },
series: series,
tooltip: { xDateFormat: '%e. %b.%Y %H:%M:%S', valueDecimals: 2, },
exporting: { enabled: true },
});
// Format the y-data.
Highcharts.numberFormat(this.y, 2, '.', ',');
});
};
答案 0 :(得分:1)
问题出在series
变量中。
首先,它是一个字符串,而不是一个对象。
我不知道你为什么这样使用它,但是如果你真的希望它是一个字符串,那么当它被赋予eval
对象时你必须series
:< / p>
...
series: eval(series)
...
此外,它不是:
series = "[{ name = 'test1', data = data[0]},{ name = 'test', data = data[1]}]"
等号不正确。 它必须是:
series = "[{ name: 'test1', data: data[0]},{ name: 'test', data: data[1]}]"
(我用冒号取代了等号。)