python - highstockchart 范围选择器 x 轴日期仅显示 1970 年 1 月 8 日至 1970 年 1 月 19 日
问题描述
我在 db 中有一个从 1931 年到昨天的数据。我正在使用 python django 模型来获取数据并显示 highstock。该图表在 x 轴上仅显示特定的 15 天,并且范围选择器也不起作用。在这里,我附上了 jsfiddle 代码供您参考......任何帮助都非常重要......过去 2 天在这个问题上遇到了问题......
Highcharts.stockChart('container', { chart: { type: 'line' }, rangeSelector: { allButtonsEnabled: true, selected: 2 }, title: { text: '% of S&P 500 members over their 50 dma' },
yAxis: [{
lineWidth: 1,
height :100,
opposite: true,
tickposition:'outside',
visible:true
}, {
lineWidth: 0,
height :100,
opposite: true,
tickposition:'outside',
top :170,
visible:true,
}],
series: [{
yAxis: 0,
name: 'S&P 500',
data: {{ sp500_series }},
color: 'green',
tooltip: {
valueDecimals: 2
}
}, {
yAxis: 1,
xAxis:0,
y :-30,
name: 'dma50',
data: {{ dma50_series }},
color: 'red',
tooltip: {
valueDecimals: 2
}
}]
});
数据样本是
系列:[{Yaxis:0,名称:'S&P 500',数据:[[[637266600.0,336.0],[637353000.0,336.87],[637439400.0,3338.07] , 341.57 ],....... ........ ......
我的输出是在此处输入图像描述
解决方案
输出是正确的。Highcharts 使用以毫秒为单位的 Unix 时间戳作为日期。您的第一个样本 x 值:637266600.0
是Thu Jan 08 1970 09:01:06 GMT+0000
例如0
is Thu Jan 01 1970 00:00:00 GMT+0000
,因此对于以前的日期,您需要使用负值。
现场演示:http: //jsfiddle.net/BlackLabel/6y3znsma/