【发布时间】:2017-05-04 08:18:03
【问题描述】:
一周前刚开始学习和使用 Highcharts。在我的应用程序中,用户从列表框中选择一个键值,然后从该键中检索一个值数组,并使用这些数据创建多个系列的折线图。在下面的屏幕截图中,第一个系列(浅蓝色)的名称为 CDEP158,而在第二个系列(黑色)中,系列名称不应为“系列 2”,而应为 CDT158。第二个系列的“系列 2”是这里的问题。
这是图表数据准备代码,它接受来自点击事件中调用的 jquery post 回调函数的dataChart(结果)。
function prepareChartData(dataChart)
{
var dataSeries = [];
var xTitle;
for (var i = 0; i < dataChart.length; i++) {
var items = dataChart[i];
var xDate = +moment(items.Time);
var seriesData = parseFloat(items.Value);
dataSeries.push([xDate, seriesData]);
xTitle = items.Name;
}
if (aeChart === undefined || aeChart === null)
{
plotChartData(dataSeries, xTitle);
return;
}
aeChart.addSeries({
title: xTitle,
data: dataSeries
});
};
创建 Highchart 的新实例及其配置的函数
function plotChartData(dataseries, xtitle)
{
aeChart = new Highcharts.Chart({
chart: {
renderTo: 'svgtrendspace',
type: 'line',
zoomType: 'xy',
panning: true,
panKey: 'shift',
plotBorderWidth: 1
},
title: {
text: ''
},
legend: {
layout: 'horizontal',
align: 'left',
itemDistance: 10,
borderWidth: 0,
itemMarginTop: 0,
itemMarginBottom: 0,
padding: 20
},
plotOptions: {
series: {
states: {
hover: {
enabled: false
}
},
dataLabels: {
enabled: false,
format: '{y}'
},
allowPointSelect: false
}
},
xAxis: {
type: 'datetime',
labels: {
rotation: -65,
style: {
fontSize: '9px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
gridLineColor: '#DDDDDD',
gridLineWidth: 0.5
},
series: [{
name: xtitle,
data: dataseries,
tooltip: {
pointFormat: '{series.name}: <b>{point.y}</b><br/>',
valueDecimals: 2
}
}]
});
};
为什么第一个系列的名称正确,而第二个却没有?我的highcharts配置错了吗?我应该如何正确配置或格式化它来解决这个问题?
我已经用谷歌搜索了与多个系列相关的类似问题,但我找不到任何可以帮助我的类似问题或答案。
非常感谢任何帮助。
【问题讨论】:
标签: javascript jquery highcharts