1π
β
Just destroy and redraw the chart. While Chart.js does support adding and removing line points β it is by label (and not by dataset β which is what you want)
Your problem was that you were emptying out the actual dataset objects β if you link it to a copy of the dataset everything works.
Here is your updated change handler
$('input:checkbox').change(function () {
var chartId = $(this).attr('data-chart-id');
var datasetId = $(this).attr('data-data-set');
dataSets[datasetId].hide = !$(this).prop('checked')
lineChartData.datasets = []
dataSets.forEach(function (dataset) {
// create a copy of the dataset to modify (if required) and put into the chart dataset array
var copy = jQuery.extend(true, {}, dataset)
if (dataset.hide)
copy.data = []
lineChartData.datasets.push(copy)
})
// create the graph from scratch
myNewChart.destroy()
myNewChart = new Chart(ctx).Line(lineChartData, chartOpt);
});
Fiddle β http://jsfiddle.net/6qdm7nwu/
Source:stackexchange.com