score:184
Yes, there is a "hidden" flag in ChartJS. eg.
data:
{
datasets: [
{
data: [1,2,3],
label: 'My First Dataset',
hidden: true,
},
],
}
See this issue on GitHub: https://github.com/chartjs/Chart.js/issues/689
score:2
If you are using angular-chartjs
, then you can add the properties of the dataset in the chart-dataset-override
property:
For example:
HTML:
<div class="container" ng-app="app" ng-controller="ChartCtrl">
<canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-series="series" chart-dataset-override="datasetOverride">
</canvas>
</div>
Javascript:
Chart.defaults.global.legend.display = true;
angular.module("app", ["chart.js"])
.controller("ChartCtrl", function($scope) {
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.datasetOverride = [{}, {
hidden: true,
}];
});
score:4
The accepted solution has the downside, that hiding/unhiding signals might sometimes fail after initializing the chart like that.
It might be a better idea to change it in the current metadata of the dataSet, which holds the actual data that is used by the chart:
chart.data.datasets.forEach((dataSet, i) => {
var meta = chart.getDatasetMeta(i);
meta.hidden = (<your-condition-here>);
});
this.chart.update();
Source: stackoverflow.com
Related Query
- Chart.js - How to set a line chart dataset as disabled on load
- How to dynamically set ChartJs line chart width based on dataset size?
- How to display Line Chart dataset point labels with Chart.js?
- how to set chart.js grid color for line chart
- How to add new dataset in line chart of chart.js by iterating over dictionary in JavaScript?
- How do you set x and y axis and Title for a line chart using charts.js?
- How do you set up a chart.js scatter line chart through angular-chart.js?
- react-chartjs-2 how to set multiple background levels within a line chart
- How to set the number of of rows in a line chart in chart.js?
- Chart.js 3.6.2, Angular 10: Logarithmic Line chart Y-Axis problems. How to set and keep Y-Axis properties, even when data changes?
- chart js 2 how to set bar width
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How set color family to pie chart in chart.js
- How to add an on click event to my Line chart using Chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- Chart.js line chart set background color
- chartjs : how to set custom scale in bar chart
- How to add an offset to a dataset in Chart js
- How to add second Y-axis for Bar and Line chart in Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- How to display value of only one datapoint in line chart
- How to align Chart.JS line chart labels to the center
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- How to create a gradient fill line chart in latest Chart JS version (3.3.2)?
- Chart.js How to set line height only to the points?
- How to draw Horizontal line on Bar Chart Chartjs
- how to programmatically make a line chart point active/highlighted
- Chart.js how to set cutoutPercentages for each dataset
- How do you set pie chart colors in angular-chart.js
More Query from same tag
- Chart.js Bar Chart coloring Technique
- How can i change a numpy.ndarray to point format with curly brackets - Python 3.7
- Chart.js pie chart not showing
- Setting max, min and stepSize values in a Chart.js graph
- How to retrieve the instance of a chart that is not global
- Cannot read property 'map' of undefined when looking at an array with no index
- Laravel trying to display chart on welcome page
- React-Chartjs-2 and Chartjs v3:Option Property
- Convert SQLite PHP array into Javascript array?
- Chart.js - Color specific parts of the background in a line chart
- Keep chart.js doughnut with fixed width and height centered in container
- Can't bind to 'data' since it isn't a known property of 'canvas'
- Fade other lines when hovering legend in Chart.js
- How can I remove two labels from my legend with an alternative to item.datasetIndex !== 1 && item.datasetIndex !== 4; ? (Charts.js)
- Pause chart.js horizontal scroll
- Chartjs Bar Chart Y Axis set base starting value to not be 0
- Hover over chart shows multiple datapoints
- angular-chart zero dimensions inside angular-strap panel
- how to show bar chart for every product
- Chart.js Treemap Custom text
- chartjs undefined length when using 2 datasets
- Pug - Access data from server in pug script(type='text/javascript')
- Uncaught Error: Can't resolve all parameters for Chart: (?, ?) in Ionic2
- chart.js show time in series
- How can i give the full Legend a background color in chart js?
- Display Doughnut Pie Chart As Circle Progress Chart.js
- Need to update tool tip value based on drop down filter after ajax call
- Change font family of labels in piechart and linechart in chartjs
- In Chart.js I want to show dotted gridLines like in below image
- Type 'Chart' is missing the following properties