mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-05 16:04:03 +01:00
Add API to change data visibility (#6907)
This commit is contained in:
@@ -147,3 +147,21 @@ Extensive examples of usage are available in the [Chart.js tests](https://github
|
||||
var meta = myChart.getDatasetMeta(0);
|
||||
var x = meta.data[0].x;
|
||||
```
|
||||
|
||||
## setDatasetVisibility(datasetIndex, visibility)
|
||||
|
||||
Sets the visibility for a given dataset. This can be used to build a chart legend in HTML. During click on one of the HTML items, you can call `setDatasetVisibility` to change the appropriate dataset.
|
||||
|
||||
```javascript
|
||||
chart.setDatasetVisibility(1, false); // hides dataset at index 1
|
||||
chart.update(); // chart now renders with dataset hidden
|
||||
```
|
||||
|
||||
## setDataVisibility(datasetIndex, index, visibility)
|
||||
|
||||
Like [setDatasetVisibility](#setdatasetvisibility) except that it hides only a single item in the dataset. **Note** this only applies to polar area and doughnut charts at the moment. It will have no affect on line, bar, radar, or scatter charts.
|
||||
|
||||
```javascript
|
||||
chart.setDataVisibility(0, 2, false); // hides the item in dataset 0, at index 2
|
||||
chart.update(); // chart now renders with item hidden
|
||||
```
|
||||
Reference in New Issue
Block a user