score:0

Accepted answer

instead of setting the dataset property to an empty object, just don't include it in the dataset at all. so

data = {
    labels: chartlabel,
    datasets: [sp, nc, spa]
};

becomes

data = {
    labels: chartlabel,
    datasets: []
};

if (sp.label !== undefined) data.datasets.push(sp)
if (nc.label !== undefined) data.datasets.push(nc)
if (spa.label !== undefined) data.datasets.push(spa)

in 2 places


replace the data insertion, point attribute setting by a loop (instead of hardcoding it for 3 datasets). so

setinterval(function() {
    currentchart.adddata([randomscalingfactor(), randomscalingfactor(), randomscalingfactor()], ++latestlabel);
currentchart.datasets[0].points[8].highlightstroke = "rgba(220,0,0,1)";
currentchart.datasets[1].points[8].highlightstroke = "rgba(0,255,0,1)";
currentchart.datasets[2].points[8].highlightstroke = "rgba(0,0,255,1)";

becomes

var d = []
currentchart.datasets.foreach(function(e) {
    d.push(randomscalingfactor())
})
currentchart.adddata(d, ++latestlabel);
currentchart.datasets.foreach(function(dataset) {
    dataset.points[8].highlightstroke = dataset.points[0].highlightstroke;
})

the highlightstroke for the new point is copied from the highlightstroke for the first point of the same series.


fiddle - http://jsfiddle.net/zs99pw4l/

score:0

currentchart2.datasets.foreach(function(e) {
    e.points[e.points.length - 1].highlightfill=e.points[0].highlightfill;
    e.points[e.points.length - 1].highlightstroke=e.points[0].highlightstroke;
});

solves the problem too. http://jsfiddle.net/co3l0bdb/5/


Related Query