Search code examples
reactjsheatmapapexcharts

Hiding single series label in legend on apex charts


I'm using heatmap chart (https://apexcharts.com/docs/chart-types/heatmap-chart/) and i would like to hide a single item in legend: the series 1 label called "label1".

enter image description here

The results would be something like:

enter image description here

So, i just want to hide a single item in legend and not the entire series


Solution

  • Easiest way would be to use pure js to hide first legend item after chart renders, like this

    document.querySelectorAll("#chart .apexcharts-legend-series")[0].style.display = "none";
    

    Second solution to hide first series using options

    legend: {
      formatter: (seriesName, opts)=>{
        if(opts.seriesIndex==0) return '' // hides first label
        return seriesName;
      },
      markers: {
        width: [0,12,12,12], // hides first marker
      }
    }