score:-1
i'm using chart.js v2.9.3
i guess you already know how to deal with cookies, here is the code that overwrites the default function that gives you an index that you can store in a cookie for further use.
onclick(e, legenditem) {
// get the index
const index = legenditem.datasetindex;
//index alert
alert("dataset index " + index + " was clicked")
// this table object
const ci = this.chart;
// show/hide dataset
var meta = ci.getdatasetmeta(index);
meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
// we hid a dataset ... rerender the chart
ci.update();
},
copy paste this code inside options > legend: {here}
finally, here is a jsfiddle live example. https://jsfiddle.net/pt0s95r7/1/
Source: stackoverflow.com
Related Query
- Chart JS - Remember hidden label state after page refresh
- Chart.js bar chart label gets hidden on hover
- How to refresh chart in django without refreshing whole page
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- VueJS + Chartjs - Chart only renders after code change
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- ChartJS fails to render one of the lines in cartesian chart following update after change to max Y axis label value
- Chart Js Change Label orientation on x-Axis for Line Charts
- ChartJS - Draw chart with label by month, data by day
- Chart Js change text label orientation on Ox axis
- chart.js scatter chart - displaying label specific to point in tooltip
- show label in tooltip but not in x axis for chartjs line chart
- Chart.js bar chart : Grid color and hide label
- Adding Chart.js line chart to Jinja2/Flask html page from JS file
- Chart JS show multiple data points for the same label
- React ChartJS prevent new data from being added into state after it's redrawn?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Chart js - Get bar width after render
- Remove the label and show only value in tooltips of a bar chart
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- Angular Chart JS prevent x label causing overflow
- Callback after line chart rendered
- chart.js - link to other page when click on specific section in chart
- PrimeNg bar chart how to show a label for the y-axis
- chart js - Apply different color for each x-axes label
- X-axis multiple colored label for bar chart using chart.js
- Chart disappears just after finishing animation
- Chart.js line chart tooltip shows wrong label when line doesn't start at first label
- Chart.js Radar chart legend label font size doesn't work
- chart.js bar chart x-axis label disappeared
More Query from same tag
- how to use chart.js with angular-chart using requirejs
- Dashed line for missing data in Chart.JS (spanGaps style)
- Tell if an line is hidden
- ChartJS is not rendered
- How to conserve user setting for hidden dataset for update?
- Unique identifier in Chartjs Bar segments?
- How to add conditional logic on Chart.js config?
- Chart.js: colouring tooltip labels
- I can't display the vue-chart.js on the page
- ChartJS Tooltips with time axis and multiple datasets
- update my chartjs form without refreshing page
- About the charts in react-native
- How to create custom legend in ChartJS
- Chart JS attempt to stacked bar chart tooltip for only one dataset
- How can I set the yAxis scale for the chart?
- HTML 5 chartjs not working as static file
- Implement ng2-charts in an Angular-Seed
- undefined labels piechart - chartjs
- Grabbing the title in plugin for ChartJS
- chart resizing in ng2-google-charts
- How to position yAxes labels in chartJS
- chart.js hide gridline inside chartarea but keep y-axis border
- Loading json file to chartjs
- Chartjs doc examples are lightning fast but same code is slow when reproducing
- Select All and Unselect Option for chart.js
- How to get data from JSON for chart.js, using vue.js
- Convert charts from vue-chartjs to a PDF
- Chartjs Legend Styling
- Styling problems with Chart.Js
- Getting the postion of the y-axis labels in chartJS