const data = {
datasets: [
{
label: 'データセット1 (線形補間)',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
borderColor: Utils.CHART_COLORS.red,
borderDash: [8, 4],
data: []
},
{
label: 'データセット2 (キュービック補間)',
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
borderColor: Utils.CHART_COLORS.blue,
cubicInterpolationMode: 'monotone',
data: []
}
]
};
const onReceive = function(event) {
this.data.datasets[event.index].data.push({
x: event.timestamp,
y: event.value
});
this.update('quiet');
};
const timeoutIDs = [];
const startFeed = (chart, index) => {
var receive = () => {
onReceive.call(chart, {
index: index,
timestamp: Date.now(),
value: Utils.rand(-100, 100)
});
timeoutIDs[index] = setTimeout(receive, Utils.rand(500, 1500));
};
timeoutIDs[index] = setTimeout(receive, Utils.rand(500, 1500));
};
const stopFeed = index => {
if (index === undefined) {
for (const id of timeoutIDs) {
clearTimeout(id);
}
} else {
clearTimeout(timeoutIDs[index]);
}
};
const start = chart => {
startFeed(chart, 0);
startFeed(chart, 1);
};
const stop = () => {
stopFeed();
};