Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove radar chart labels in chart.js

I'm trying to get rid of the label "undefined" from showing at all at the top of my chart, as I only have one dataset and don't need a legend.

https://i.sstatic.net/MJy51.png

Here's my code:

// Radar chart data
var radarData = {
labels : ["Abs","Arms","Back","Butt","Chest","Legs","Shoulders"],
datasets : [
    {
  lavel: "test",
        fillColor: "rgba(102,45,145,.1)",
        strokeColor: "rgba(102,45,145,1)",
        pointColor : "rgba(220,220,220,1)",
        pointStrokeColor : "#fff",
        data : [65,59,90,81,56,55,40]
    }
]
};

// Create Radar chart
var ctx = document.getElementById("radarChart").getContext("2d");

var myNewChart = new Chart(ctx, {
type: "radar",
data: radarData
});

Adding "options: [scaleShowLabels=false]" doesn't work for some reason.

like image 674
watMartin Avatar asked Sep 14 '25 04:09

watMartin


2 Answers

var myNewChart = new Chart(ctx, {
            type: "radar",
            data: radarData,
        });
        myNewChart.options.title.text = "top of chart";   // test, total fail
        myNewChart.options.legend.display = false;        // This one does it!

So apparently on the radar chart, that top element is called the legend. I was able to place a watch on myNewChart object in Chrome and step thru the code in dev tools.

like image 171
zipzit Avatar answered Sep 15 '25 17:09

zipzit


Keep in mind that in Chart.js version 3, the options now have a plugins inner field, in which such options are to be configured. So now it is:

options:{
      plugins:{
         legend:{
            display:false
         }
      }
   }

Or programmatically:

myNewChart.options.plugins.legend.display = false;
like image 45
Paul Isaris Avatar answered Sep 15 '25 18:09

Paul Isaris