<div style="width: 600px; height: 300px;">
<canvas id="myChart" style="width: 100%; height: 100%;"></canvas>
<div id="legend"></div>
</div>
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fill: false,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
data: [65, 59, 80, 81, 56, 55, 40],
},
{
label: "My Second dataset",
fill: false,
backgroundColor: "green",
borderColor: "green",
data: [60, 159, 40, 53, 53, 65, 40],
}
]
};
var myChart = new Chart('myChart', {
type: 'line',
data: data,
options: {
legend: {
display: false
},
}
});
$('#legend').html(myChart.generateLegend())
$("#legend").on('click', "li", function(){
var i = $(this).index()
myChart.data.datasets[i].hidden = !myChart.data.datasets[i].hidden;
myChart.update();
})