reactjsapexcharts

Add spacing around datalabels in React Apexcharts library


I am using React Apexcharts library to plot the chart. I am having trouble adding space around the datalabels in a pie chart. Can anyone help in this?

const pieChartOptions = {
    labels: ["Above Ground", "Under Ground", "Divider"],
    chart: {
      width: "50px",
    },
    colors: ["#FF8C33", "#4472C4", "#EFF4FB"],
    states: {
      hover: {
        filter: {
          type: "none",
        },
      },
    },
    legend: {
      show: false,
    },
    dataLabels: {
      enabled: true,
      formatter: function (val, opts) {
        return opts.w.globals.series[opts.seriesIndex];
      },
      style: {
        fontSize: "18px",
      },
      dropShadow: {
        enabled: true,
        left: 2,
        top: 2,
        opacity: 0.7,
      },
    },
    hover: { mode: null },
    plotOptions: {
      donut: {
        expandOnClick: false,
        donut: {
          labels: {
            show: false,
          },
        },
      },
    },
    fill: {
      colors: ["#FF8C33", "#4472C4", "#EFF4FB"],
    },
    tooltip: {
      enabled: true,
      theme: "dark",
    },
  };

Is there any property that I can add to my dataLabels to achieve the spacing? I tried adding offsetX and offsetY but didn't work. pie-chart


Solution

  • For donut and pie charts you can use the offset property. Negative values will move the labels further inside, and positive values will move it further outside.

    options = {
      plotOptions: {
        pie: {
          dataLabels: {
            offset: -50
          }
        }
      }
    }
    

    The offsetX and offsetY properties adjust the offset to the left and above the entire donut/pie area respectively.