highstock remove series 後動態新增series

jiangzhengdong發表於2013-03-24

具體效果參考我在jsFiddle的例子:http://jsfiddle.net/7pKV9/,程式碼如下:


<div id="container" style="height: 400px; min-width: 600px"></div>

<button id="button">Remove series and Add series</button>

<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/samples/data/three-series-1000-points.js"></script>

$(function() {
	$('#container').highcharts('StockChart', {

	    scrollbar: {
            enabled: true
        },

        navigator: {
            enabled: true
        },

	    rangeSelector: {
	    	selected: 1
	    },

        series: [{
			name: 'MSFT',
			data: MSFT
        }]
	});

	$('#button').click(function() {
		var chart = $('#container').highcharts();
        
        for(var i=0;i<chart.series.length;i++)
            chart.series[i].remove();
        
        chart.addSeries({
			name: 'ADBE',
			data: ADBE
        });
        chart.addSeries({
			name: 'MSFT',
			data: MSFT
        });
        $(this).attr('disabled', true);
	});   
});


相關文章