以下代码显示空白图表(轴和标题显示正常但没有数据),我无法理解原因。它似乎不是数据格式问题,因为我遵循文档。将选项记录到Firebug会显示“series”为空。
var chart1;
var data;
options = {
chart: {
renderTo: 'container',
animation: Highcharts.svg,
},
rangeSelector: {
enabled: true
},
navigator: {
enabled: true
},
xAxis: {
type: 'datetime'
},
yAxis: { //--- Primary yAxis
title: {
text: 'Volume'
}
},
series: [{
name: 'name',
step: true,
data: data
}]
};
console.log(options); //series is null here !
function readData() {
//using foo data here, actually getting it via AJAX, and that works OK
data = [[0,1],[1,2],[2,3]];
alert("data created");
//this checks that the data loaded OK
document.getElementById("result").innerHTML = "";
for (var i = 0; i < data.length; i++) {
document.getElementById("result").innerHTML += 'Key: ' + data[i][0] + '; Value: ' + data[i][1] + "<br />";
}
chart1 = new Highcharts.StockChart(options);
}
以下是我的内容:
<head>
<title>Title</title>
<meta charset="UTF-8">
<script type="text/javascript" src="XHR.js"></script><!-- unrelated (for ajax) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/stock/highstock.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js" type="text/javascript"></script>
<script type="text/javascript"> ... </script>
</head>
答案 0 :(得分:0)
当然数据为空,因为您没有将其设置为选项,请添加以下行:
options.series[0].data = data;
来自AJAX的数据来了。例如,在创建图表(chart1 = ...
)之前。