Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

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

Open
myungsunscott opened this issue Jan 29, 2018 · 3 comments
Open

Comments

@myungsunscott
Copy link

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
Copy link
Author

Hey @moberwasserlechner Brilliant addon, thanks for the contribution.

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

@freelancer1845
Copy link

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

@dosindi
Copy link

dosindi commented Jul 4, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants