Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js v2 hide dataset labels

I have the following codes to create a graph using Chart.js v2.1.3:

var ctx = $('#gold_chart'); var goldChart = new Chart(ctx, {     type: 'line',     data: {         labels: dates,         datasets: [{             label: 'I want to remove this Label',             data: prices,             pointRadius: 0,             borderWidth: 1         }]     } }); 

The codes look simple, but I cannot remove the label from the graph. I tried a lot of solutions I found online, but most of them use Chart.js v1.x.

How can I remove the dataset labels?

like image 554
Raptor Avatar asked May 13 '16 07:05

Raptor


People also ask

How to hide label in dataset in chart js?

You can hide datasets labels in Chart. js by applying 'display: false' into legend option.

How to hide data in chart js?

In ChartJS's pie and doughnut charts there is a legend option for every data that you can click to hide the data, this behavior changes with bar and line charts, when there is only a single legend option for the entire dataset, and when clicking it, it hides the entire dataset.

What is legend in ChartJS?

The chart legend displays data about the datasets that are appearing on the chart.


1 Answers

Just set the label and tooltip options like so

... options: {     legend: {         display: false     },     tooltips: {         callbacks: {            label: function(tooltipItem) {                   return tooltipItem.yLabel;            }         }     } } 

Fiddle - http://jsfiddle.net/g19220r6/

like image 167
potatopeelings Avatar answered Sep 28 '22 05:09

potatopeelings