vaadin-chartjs icon indicating copy to clipboard operation
vaadin-chartjs copied to clipboard

Push a single new data point to simple charts (Such as Line Chart)

Open myungsunscott opened this issue 7 years ago • 3 comments

Great addon. I really appreciate the work you've put into it!

I'm just wondering if there's a way to push new data points to charts that have already been created?

Here's an example of what I mean: (http://www.chartjs.org/samples/latest/charts/line/basic.html)

If you press the "Add Data" button, a single new points appears as part of the LineDataSet. I guess that button is just doing the following: http://www.chartjs.org/docs/latest/developers/updates.html

I haven't found a way to do this yet without clearing all the data, rebuilding the dataset, adding the rebuilt dataset and refreshing the chart. This does not produce the same behaviour as the demo in the link above though.

myungsunscott avatar Jan 29 '18 16:01 myungsunscott

Hey @moberwasserlechner Brilliant addon, thanks for the contribution.

Do you think you might support this feature in an upcoming release?

myungsunscott avatar Mar 29 '18 08:03 myungsunscott

Hey,

what worked for me is giving each dataset a UUID and update them in the javascript connector like that.

for (var i = 0; i < chartjs.data.datasets.length; i++) {
      var dataset = chartjs.data.datasets[i];
      var stateDataSet = undefined;
      for (var l = 0; l < this.getState().configurationJson.data.datasets.length; l++) {
        	if(this.getState().configurationJson.data.datasets[i].UUID == dataset.UUID) {
        		stateDataSet = this.getState().configurationJson.data.datasets[i];
        		 break;
                 }
      }
      if (stateDataSet !== undefined) {
        	dataset.data = stateDataSet.data;
       }
}

The obvious problem is, that all datapoints are always pushed through the websocket (instead of only those that should be deleted / added). Maybe the data of the datasets should be removed from "configurationJson" and a field like "dataToPush" and "dataToRemove" (mapping the data through UUIDs of the datasets) should be added. Of course you could miss datapoints if there is a connection issue, but maybe even that could be detected if wanted.

Cheers

Jascha

freelancer1845 avatar Jun 18 '18 21:06 freelancer1845

Interesting discussion, I also encountered a similar issue. Looking forward for a simpler workaround.

dosindi avatar Jul 04 '19 06:07 dosindi