score:1
Accepted answer
chart.js has an example for a html legend on their sample page: https://www.chartjs.org/docs/master/samples/legend/html.html
li.onclick = () => {
const {type} = chart.config;
if (type === 'pie' || type === 'doughnut') {
// pie and doughnut charts only have a single dataset and visibility is per item
chart.toggledatavisibility(item.index);
} else {
chart.setdatasetvisibility(item.datasetindex, !chart.isdatasetvisible(item.datasetindex));
}
chart.update();
};
the chart
and item
here are argument in the plugin callback so if you are implementing it yourself without use of the plugin you will need to reference your own chart object and manage which index you clicked and then call the setdatasetvisibility
or toggledatavisibility
for that index
Source: stackoverflow.com
Related Query
- Chart.js dataset options externally with functionality
- How to display Line Chart dataset point labels with Chart.js?
- Using chart js options with react-chartjs-2 and typescript
- Updating chart.js chart with dataset of different size
- chart.js pie chart - how to update dataset with smooth transition
- Create stacked bar chart with a single dataset per stack
- ChartJS pie chart with simple parsing options doesn't render, only works when set as bar/line chart
- what is wrong with my code ? java script chart position
- Chart options not used with chart js
- problem with chart js pie chart dataset data
- jQuery - destroy and rebuild chart with original options
- Chart.js - How to set a line chart dataset as disabled on load
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Chart.js Line-Chart with different Labels for each Dataset
- How to prevent first/last bars from being cut off in a chart with time scale
- ChartJS - Draw chart with label by month, data by day
- Horizontal stacked bar chart with chart.js
- line chart with {x, y} point data displays only 2 values
- Vertical stacked bar chart with chart.js
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Dynamically update the options of a chart in chartjs using Javascript
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- How to fix chart Legends width-height with overflow scroll in ChartJS
- Add DataSet Bar Chart - Chart.JS
- chart js how to fill legend box with colour
- How to add an offset to a dataset in Chart js
- Chart.js Mixed Bar and Line chart with different scales
More Query from same tag
- How do I display a different chartjs tooltip title?
- How to create a line chart indicating which month a user wrote more or less blogs?
- Horizontal bar chart in chart.js
- Chart.js - Ajax response not accept
- Chart JS not re rendering in Laravel Livewire
- How to populate entire box inside a React chart (between two axes)
- Chart.js Bar graph with percentage values
- How to put 2 labels and distinct tooltips from two bars
- Remove the vertical line in the chart js line chart
- onZoom not triggered when zooming
- How use my data with Charts.js in my case?
- chart js: when all the values passed to data are zeros, nothing is showing
- Chart.js Tooltips customization
- How to write with good practice?
- Is there a way to adjust only the bottom padding of a chart's title in Chart.js?
- Highlight chart element when hovering over its corresponding legend Item
- Fetch more data for line chart onZoom/onPan issues
- Bar chart with two sets of labels in Quickchart
- Chart.js doughnut chart comes bigger and bigger
- Chart.js Legend Padding-Left
- Is it possible to merge duplicate labels (and their datas) into one column in Chart Js?
- Empty circle - only point strok in line chart for ChartJS
- Chart js, Canvas is null polymer project
- chart.js - problems with axes options - what am I doing wrong?
- Chart.js load new data from saved JSON object
- How do I obtain a Chart instance for Chart.js
- Update a chart dynamically with socket.io in real time
- Set Global Config on Angular Charts Not Working
- Chart Js change text label orientation on Ox axis
- pie chart label undefined ionic 3