我有 Highchart LINE类型图,它正确显示了线图。我有动态更改数据的按钮。第一个图表呈现7天数据。点击14天图表正确呈现数据,但我使用的时间。
function requestData(response,point){
...data fetching code......
var series = chart.series[0];
chart.series[1].setData(eval(oneArray),false,true);
chart.series[0].setData(eval(twoArray),false,true);
chart.xAxis[0].setCategories(json array, true,true);}
如果我删除chart.xAxis[0].setCategories(json array, true,true);
然后它显示具有正确数据的行但x轴只是数字,我必须设置x轴与天名.json数组显示所有正确。
这是我的图表代码。
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: "progresschart",
type: "line",
events: {
load: requestData
}
},
credits: {
enabled: false
},
title: {
text: "Calories Burned Vs Calorie Consumed"
},
xAxis: {
categories: [],
},
yAxis: {
title: {
text: "Calories"
},
},
series: [{
name: "Consumed",
data:[]
},{
name: "Burned",
data:[]
}],
exporting: {
enabled: false
}
});
});
首先,类别数组是:
["Thu,28th", "Fri,29th", "Sat,30th", "Sun,1st", "Mon,2nd", "Tue,3rd", "Wed,4th"]
要设置的类别数组是:
["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"]
系列[1]:
[403.91604166667, 0, 0, 156.421875, 190.48708333333, 121.66145833333, 52.140625, 104.28125, 440.41447916667, 472.04645833334, 0, 178.3209375, 191.18229166666, 139.04166666667]
系列[2]:
[100, 112, 0, 0, 360, 330, 141, 150, 100, 0, 0, 0, 0, 0]
答案 0 :(得分:5)
这可能是旧版Highcharts中的错误,更新到3.0.7+应解决该问题。
工作示例:http://jsfiddle.net/24dXX/
代码:
var arr = ["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"],
oneArray = "[403.91604166667, 0, 0, 156.421875, 190.48708333333, 121.66145833333, 52.140625, 104.28125, 440.41447916667, 472.04645833334, 0, 178.3209375, 191.18229166666, 139.04166666667]",
twoArray = "[100, 112, 0, 0, 360, 330, 141, 150, 100, 0, 0, 0, 0, 0]";
chart.series[1].setData(eval(oneArray), false, true);
chart.series[0].setData(eval(twoArray), false, true);
chart.xAxis[0].setCategories(arr, true, true);