Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Support for a missing data value in line chart

Open peterdom opened this issue 13 years ago • 12 comments

When adding two lines to one chart there is always the issue that there are a few missing data values in each line. i.e. Jan Feb Mar Apr Line 1 has values for Jan, Feb and Apr Line 2 has values for Feb, Mar

At the moment there HAS to be a value for any label.

Please add the possibility to add a "null" value which causes the line connecting from the value before to the value after without plotting a value for the "null" part.

peterdom avatar Mar 30 '13 10:03 peterdom

I also have this issue.

davidblurton avatar Apr 18 '13 12:04 davidblurton

+1 this would be great to have!

timclipsham avatar May 07 '13 11:05 timclipsham

I tried to replace some value by NaN, but it didn't work. This would definitly be useful.

thibault avatar Aug 15 '13 15:08 thibault

+1 - it would be extremely useful!

djogopatrao avatar Nov 13 '13 23:11 djogopatrao

+1

achudars avatar Jan 12 '14 20:01 achudars

+1

linagee avatar Apr 14 '14 19:04 linagee

This would be great

warksit avatar Apr 14 '14 22:04 warksit

You can just make it skip over doing the drawing iteration for that line if its null. (Took me forever to find where its doing the line drawing.) The way it works before this is it will interpret null as zero.

822: for (var j=1; j<data.datasets[i].data.length; j++){ if (!data.datasets[i].data[j]) { continue; } 823: if (config.bezierCurve){

845: for (var k=0; k<data.datasets[i].data.length; k++){ if (!data.datasets[i].data[k]) { continue; } 846: ctx.beginPath();

linagee avatar Apr 14 '14 23:04 linagee

The proposed solution by Linagee has some problems (curve and filling are not correct; solution not valid when the first value is missing).

In the alternate version that you will find at https://github.com/FVANCOP/ChartNew.js, I have implemented a solution that is more accurate. This version is down compatible with Nick's version.

Sample data that works in the alternate version :

var mydata1 = { labels : ["January","February","March","April","May","June","July"], datasets : [ { fillColor : "rgba(220,220,220,0.5)", strokeColor : "rgba(220,220,220,1)", pointColor : "rgba(220,220,220,1)", pointStrokeColor : "#fff", data : [0.65,0.59,0.90,0.81,0.56,0.55,1.00], title : "pFirst data" }, { fillColor : "rgba(151,187,205,0.5)", strokeColor : "rgba(151,187,205,1)", pointColor : "rgba(151,187,205,1)", pointStrokeColor : "#fff", data : [,0.34,,"0.19",0.96,0.27,], title : "pSecond data" } ] }

The alternate version also support negative values (which is not the case in Nick's version).

FVANCOP avatar Apr 15 '14 20:04 FVANCOP

Would also like to see this feature in the main Chartjs. The new Chartjs has some nice new features. Both together would be great.

ghost avatar Jul 22 '14 21:07 ghost

+1

Aelios avatar Aug 01 '14 14:08 Aelios

Being worked on here: https://github.com/nnnick/Chart.js/pull/435

Closing this as duplicate of this.

nnnick avatar Aug 01 '14 15:08 nnnick