重现步骤。
- 我们有一个显示 4 个系列数据的图表,每个系列都有相应的图例。
- 初始图表加载了 1 年的数据。
- 然后,我们通过单击 4 个图例从图表中删除所有数据系列
- 然后我们更改图表的缩放级别 - 例如从 6 个月缩放到 3 个月缩放。(注意:我们更改缩放而不显示数据系列)。
- 然后,我们通过单击图例重新启用数据系列。
图表未正确重绘。要让图表重绘,我们必须重新加载整个页面。
<script src="http://code.highcharts.com/stock/highstock.js"></script> <script src="http://code.highcharts.com/stock/modules/exporting.js"></script> <div id="container" style="height: 500px; min-width: 600px"> </div> $(function() { var seriesOptions = [], yAxisOptions = [], seriesCounter = 0, names = ['MSFT', 'AAPL', 'GOOG'], colors = Highcharts.getOptions().colors; $.each(names, function(i, name) { $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) { seriesOptions[i] = { name: name, data: data }; // 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++; if (seriesCounter == names.length) { createChart(); } }); }); // create the chart when all data is loaded function createChart() { chart = new Highcharts.StockChart({ chart: { renderTo: 'container' }, navigator: { enabled: false }, legend: { enabled: true }, rangeSelector: { selected: 4 }, scrollbar: { enabled: false }, 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 }); }
});