forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Updating Charts | ||
|
||
It's pretty common to want to update charts after they've been created. When the chart data is changed, Chart.js will animate to the new data values. | ||
|
||
## Adding or Removing Data | ||
|
||
Adding and removing data is supported by changing the data array. To add data, just add data into the data array as seen in this example. | ||
|
||
```javascript | ||
function addData(chart, label, data) { | ||
chart.data.labels.push(label); | ||
chart.data.datasets.forEach((dataset) => { | ||
dataset.data.push(data); | ||
}); | ||
chart.update(); | ||
} | ||
``` | ||
|
||
```javascript | ||
function removeData(chart) { | ||
chart.data.labels.pop(); | ||
chart.data.datasets.forEach((dataset) => { | ||
dataset.data.pop(); | ||
}); | ||
chart.update(); | ||
} | ||
``` | ||
|
||
## Preventing Animations | ||
|
||
Sometimes when a chart updates, you may not want an animation. To achieve this you can call `update` with a duration of `0`. This will render the chart synchronously and without an animation. |