问题
I have problem with Highstock navigator always displaying 1970-1-1 as a start point when creating dynamic series and data... does anyone have encountered this issue and has some workarounds?
Here is an example: http://jsfiddle.net/sokarovski/SRtvn/
var $container = $('.canvas');
var chart = new Highcharts.StockChart({
chart: {
renderTo: $container[0]
},
xAxis: {
type: 'datetime' ,
ordinal: false
}
});
chart.addSeries({
data: [
[Date.UTC(2013,1,1), 0],
[Date.UTC(2013,1,5), 10],
[Date.UTC(2013,1,15), 15],
[Date.UTC(2013,2,5), 20],
[Date.UTC(2013,2,28), 25],
[Date.UTC(2013,3,3), 30],
]
});
//I tried to fix it with this also but it does not help
chart.xAxis[0].setExtremes(Date.UTC(2013,1,1), Date.UTC(2013,3,3));
回答1:
It is caused, that navigator doesn't work properly, when you try to addSeries / addPoint to chart which have no series / data. This bug is reported here:
https://github.com/highslide-software/highcharts.com/issues/624
回答2:
What we do is we pre-fetch our data we want to add to the chart and take the first point and create a series on the stock chart with just that one point. We then call the add data code to add the rest of the points such that the chart "plays".
Now, if you do not know what data you are going to get first (for example you let the user click a button to show data1 or data2 and you do not have a default) you can create your chart - but hide it. By using the loading options. So, you create an empty chart and do not show it until such time the user has selected the data.
来源:https://stackoverflow.com/questions/15248564/highstock-navigator-always-starts-from-1970-1-1