Where is the documentation about adding and removing Data?
I cannot find it here: http://www.chartjs.org/docs
I would like to know exactly what parameters the addData and removeData functions have.
@SonicTTH are you using v1? Thise functions existed then.
In v2, you can simply update the data object on the chart before calling update()
Okay thank you so far. Figured out that the chart.js wrapper im using for my asp.net plattform uses chart.js v1.
Okay so when I use v2 now. what do you mean by update tha data object? How can I add values to that?
The best way to describe it is to look at the sample files. https://github.com/chartjs/Chart.js/blob/master/samples/line/line.html#L115
Okay awesome found out how to correctly add data to the charts, so that it comes in from the right side.
But the remove method there (using splice) removes entries at the end of the chart. I want to create a flowing line chart where new data comes from right and is removed at the left.
Using shift() on both the labels and the datasets removees the first element correctly:
config.data.labels.shift(); // remove the label first
config.data.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.shift();
});
window.myLine.update();
But the lines are flying around like hell!
In v1, the removeData() function correctly removed a datapoint at the left end of the chart (beginnig of the array I guess) and had all the lines move leftwards in a scrolling manner.
The animation of the chart in v2 it so that it looks very weird with all the lines flying around instead of simply moving to the left.
Is this achievable somehow?
I presume you're using the latest release, 2.3.0? You could try the latest from the master branch. We made improvements since the last release that may fix your problem
I would like to try that but I dont know how to get a working chart.js from the master branch. I cant compile or gulp it as ive read here somewhere since I have no tools for that. Can I get a compiled latest version somehow?
Duplicates #1997, might be interesting for you to read this thread. As @etimberg said, you need the upcoming (very soon) version 2.4 which fixes exactly the issue you are experiencing. There is a built alpha / dev version attached to this comment that you can use for testing.
@SonicTTH You can download built files from the releases page.
On a side note, v1 documentation is available here.
How to get json data and render to chart?
@vajrayanu That is something that you have to do on the client side. Charts can be created as shown in the docs.
I have found a workaround for the gap animation issue when removing old data. By setting the value of the first point to the second, then removing the second. Its a bit dirty, but I don't know of any other way of doing this.
if (this.chartData.datasets[0].data.length > 5) {
this.chartData.labels.shift()
this.chartData.datasets.forEach(dataset => {
dataset.data[0] = dataset.data[1]
dataset.data.splice(1, 1)
})
}
Data update docs in #4170
Is there any news on this issue with the gap animation after shift().
We are talking about this in https://github.com/valor-software/ng2-charts/issues/291 as well.
Would be great to find a proper solution for this.
@everystone, thanks for this workaround. Not perfect, but the best I have seen so far.
As this issue is closed I'll open a new one related to the animation gap.
See https://github.com/chartjs/Chart.js/issues/4695.
Go to https://www.chartjs.org/docs/latest/developers/updates.html