我只是想通過函數調用來改變highcharts中的數據系列。但似乎我無法訪問它。我知道「系列」是未定義的。我也嘗試使用類似於'按鈕單擊'方法(http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-addpoint-append/)失敗的方法。Highchart,使用參數編輯來自函數調用的數據
任何幫助是極大的讚賞 BR克里斯蒂安
var mainchart;
function addGraphData(a) {
mainchart.series[0].addPoint(a);
}
$(function() {
$('#container').highcharts({
chart: {
defaultSeriesType: 'line',
events: {
load : function() {
mainchart = this; // `this` is the reference to the chart
}
}
},
title: {
text: 'Kobber (KJ-040)'
},
xAxis: {
text: 'Dato'
},
yAxis: {
title: {
text: 'Resultater'
}
},
series: [{
//name: 'Metall data',
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
})
$(function() {
$('#container').highcharts({
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
// the button action
var i = 0;
$('#button').click(function() {
var chart = $('#container').highcharts();
chart.series[0].addPoint(50 * (i % 3));
i += 1;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
<button id="button" class="autocompare">Add point</button>
如果你打你的'addGraphData()'函數? – Kabulan0lak
Im實際上首先在窗口加載時調用createGraph()函數,然後調用addGraphData()。我想在某些特殊事件中全局調用該函數。我怎樣才能做到這一點?請記住,即時通訊完全neewbie在jQuery中。 – KB87
只需調用createGraph(),然後爲要添加的每個點調用addGraphData()。我真的不明白你的問題。 – Kabulan0lak