Search code examples
vue.jsvuejs3apexcharts

VUE3 dataLabels stacked column apex chart


I want show only top total datalabels but is dublicate label

enter image description here

dataLabels: {
    enabled: true,
    offsetY: -20,
    style: {
      fontSize: "12px",
      colors: ["#304758"],
    },

    formatter: function (value, { seriesIndex, dataPointIndex, w }) {
      return w.globals.stackedSeriesTotals[dataPointIndex];

    },
  },

Solution

  • Here is formatter I come up with, should work for any number of series

    formatter: function (value, { seriesIndex, dataPointIndex, w }) {
      let numberOfSeries = w.config.series.length - 1
      if(seriesIndex == numberOfSeries){
        return w.globals.stackedSeriesTotals[dataPointIndex];
      } else if (seriesIndex<numberOfSeries){
        let sum = 0
        while (seriesIndex < numberOfSeries) {
          seriesIndex++;
          sum+= w.config.series[seriesIndex].data[dataPointIndex] || 0
        }
        if (sum === 0) return w.globals.stackedSeriesTotals[dataPointIndex];
      }
    },