【发布时间】:2015-01-29 09:26:24
【问题描述】:
我正在研究股票图表,我必须在其中显示三种货币的股票数据。我能够看到与之对应的图表和费率,但 x 轴上的日期不正确。我的 json 响应是这样的。
[{"rate":1.3349,"month":"1422403200000"},{"rate":1.3415,"month":"1422316800000"},{"rate":1.3394,"month":"1422230400000"},{"rate":1.3202,"month":"1421971200000"},{"rate":1.304,"month":"1421884800000"},{"rate":1.3109,"month":"1421798400000"},{"rate":1.3017,"month":"1421712000000"},{"rate":1.3114,"month":"1421625600000"},{"rate":1.305,"month":"1421366400000"},{"rate":1.292,"month":"1421280000000"},{"rate":1.2876,"month":"1421193600000"},{"rate":1.2819,"month":"1421107200000"},{"rate":1.2801,"month":"1421020800000"}]
它只是一个 json 响应的例子。在我的 java 中,vo rate 是 double 类型,而 month 是 String 类型。
我的js代码在这里
function drawChart(){
var seriesOptions = [],
seriesCounter = 0,
names = ['EURGBP', 'EURJPY', 'EURCHF'],
// create the chart when all data is loaded
createChart = function () {
$('#drawchart').highcharts('StockChart', {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
});
};
$.each(names, function (i, name) {
$.getJSON('/bin/drawChart, function (data) {
var dataArray = new Array;
$.each(data, function (i, obj) {
dataArray.push([obj.month,obj.rate]);
});
alert(dataArray);
seriesOptions[i] = {
name: name,
data: dataArray,
tooltip: {
valueDecimals: 2
}
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter += 1;
if (seriesCounter === names.length) {
createChart();
}
});
});
}
为什么日期在 x 轴上显示不正确
【问题讨论】:
标签: javascript jquery json highcharts highstock