linechart - How to set global/specific properies when updating line-chart using Chart.js? -
this situation http://jsfiddle.net/co3l0bdb/4/
thanks @potatopeelings able set property highlightfill datasets , works when show/hide series in graph. added:
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)"; but get, but not want, when hide series, after 2 iteration starts plot hidden data , stops remove firsts data of series. how can set series-spefic properties, such highlightstroke, without described side effect?
instead of setting dataset property empty object, don't include in dataset @ 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 data insertion, point attribute setting loop (instead of hardcoding 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 new point copied highlightstroke first point of same series.
fiddle - http://jsfiddle.net/zs99pw4l/
Comments
Post a Comment