score:1
Accepted answer
you can use the filter on the labels of the legend to filter out the datasets you dont want to show in the legend, see example:
var options = {
type: 'bar',
data: {
labels: ["red", "blue", "yellow", "green", "purple", "orange"],
datasets: [{
label: '# of votes',
data: [12, 19, 3, 5, 2, 3],
borderwidth: 1,
backgroundcolor: 'red'
},
{
label: '# of points',
data: [7, 11, 5, 8, 3, 7],
borderwidth: 1,
backgroundcolor: 'blue'
},
{
label: 'dont show this',
data: [17, 1, 15, 18, 13, 17],
borderwidth: 1,
backgroundcolor: 'orange'
}
]
},
options: {
plugins: {
legend: {
labels: {
filter: (legenditem, chartdata) => (legenditem.text !== 'dont show this')
}
}
}
}
}
var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
<canvas id="chartjscontainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.3.2/chart.js"></script>
</body>
documentation: https://www.chartjs.org/docs/master/configuration/legend.html#legend-label-configuration
Source: stackoverflow.com
Related Query
- Legend for only specific datasets - chart.js
- ChartJs(Java) Can I remove only specific gridLines for a Linear Chart withouth removing the labels on xAxis?
- Chart JS, Choose different Y-axis for different datasets
- Using Chart.js - Creating Legend for Doughnut Chart
- Multiple bubble chart datasets for chartjs
- ChartsJS make number in middle for only one chart
- Empty circle - only point strok in line chart for ChartJS
- Can you change legend style for bar datasets with chart.js?
- React with chart js, labelling problems in multiple datasets for doughnut chart
- I cant get Legend to work for my chartjs donut chart
- Resize Chart Independently From Legend in ChartJS for Canvas Download
- Charts JS: Doughnut chart and hiding tooltip for specific data index within each dataset
- chart.js legend not working for pie chart
- Why ChartJS's Bar Chart does not render bar for a specific value?
- ChartJS Only Show Large Font Size for a Specific Tick
- I want to add label on only specific vue chart
- VueJS + Chartjs - Chart only renders after code change
- How can I change only a specific option in a chart with chart.js?
- ChartJS: Custom legend not showing Labels for Multi-Pie chart
- React-chart does not render the legend for PIE chart
- Chart JS attempt to stacked bar chart tooltip for only one dataset
- getting additional value fields from data source for dx.chartjs doughnut chart
- Chartjs Custom Legend for Doughnut Chart Having Labelled Lines Sticking Out of Each Section
- How to hide the legend display for a specific chart?
- Changing borderDash for specific gridLines in radar chart
- Displaying line chart for multiple datasets using chart.js
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chart Js Change Label orientation on x-Axis for Line Charts
- Chart.js - Increase spacing between legend and chart
- Chartjs random colors for each part of pie chart with data dynamically from database
More Query from same tag
- Why is ChartJS combining two charts?
- vue-chartjs remove top rectangle (datasets label)
- Problem in passing values using props in react.js while using chart.js
- Django and Chartjs template conflict
- Chart.js: show tooltip color square only for certain row
- How to set max/min on x axis to display time range in Chart.js?
- Multiple Axis Line Chart
- Draw chart.js as svg
- how to render the same chart using Chart.js
- How do I display a chart with chart.js?
- ReferenceError: Chart is not defined - chartjs
- Chart.js - Remove empty space in pie chart
- ChartJs Force scatter plot to be square shaped
- Chart JS Tooltip - place it in a fixed location outside the canvas
- chart.js - How draw x and y axes lines on the left and bottom
- Chart.js (Radar Chart) different scaleLineColor for each scaleLine
- Bars on chartjs superimpose when using type: 'time'
- Chart JS Displays Only Bigger Dataset But Has Both Datasets?
- Chartjs drill down issue with multiple Y-Axis Bar/Line graph
- Lograthmic yaxsis setting not working in chartjs
- How to get onClick Event for a Label in ChartJS and React?
- Replace a Canvas Pie Chart Onclick
- ChartJS "Unable to get property 'getTime' of undefined or null reference"
- Chart.js - Multiple Doughnut Charts on same Canvas
- Calling a TypeScript function from a Chart.js option callback
- How To Format Scale Numbers in Chart.js v2
- chart.js renders outside div and canvas
- How to ensure that a Chart.js line chart uses all space available on the y-axis?
- How to get chartjs column chart in ng-repeat
- Execute chartjs after an ajax call with PHP