I'm trying to create a multiple series version of this: http://jsfiddle.net/j5qzcu68/2/
The random generator for this works fine for one series:
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x1 = Math.random(),
y1 = Math.random(),
x2 = Math.random(),
y2 = Math.random();
series.addPoint([x1, y1], true, true);
}, 1000);
}
}
My effort to pass two series of xy values is this: http://jsfiddle.net/j5qzcu68/6/ HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
JAVASCRIPT
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts({
chart: {
type: 'scatter',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x1 = Math.random();
y1 = Math.random();
x2 = Math.random();
y2 = Math.random();
series.addPoint([[x1, y1], [x2, y2]], true, true);
}, 1000, true);
} //load function
}
},
title: {
text: 'Random data'
},
plotOptions: {
series: {
lineWidth: 1
}
},
xAxis: {
min: 0,
max: 1,
title: {
text: 'Value'
}
},
yAxis: {
min: 0,
max: 1,
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Fish1',
data: [0, 0]
}, {
name: 'Fish2',
data: [0, 0]
}]
});
});
});
Adapting the addPoint method to the following doesn't work:
series.addPoint([[x1, y1], [x2, y2]], true, true);
Do I need to wade into JSON pre-processing or is there a simple answer on how to pass this array for multiple series?
You need to use two series and refer to them separaterely.
setInterval(function () {
var x1 = Math.random();
y1 = Math.random();
x2 = Math.random();
y2 = Math.random();
serie1.addPoint([x1, y1], false, true);
serie2.addPoint([x2, y2],true,true);
}, 1000, true);
Example: http://jsfiddle.net/j5qzcu68/8/
您需要添加两个不同的点,例如
series.addPoint([x1, y1], true, true); series.addPoint([x2, y2], true, true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.