apexcharts with vue - pie chart seriesIndex and dataPointIndex are -1 for click

apexcharts with vue - pie chart seriesIndex and dataPointIndex are -1 for click

我正在使用 Vue apexcharts,每当我点击饼图时,我都会看到:

options: {
          chart: {
            events: {
              click:
                  (event: any, chartContext: any, config: any) => {
                    console.log('Clicked', chartContext);
                    console.log('Event', event);
                    console.log('Config', config);
                  }
            },
          },

在控制台中,config.seriesIndexconfig.dataPointIndex 始终是 -1 - 如何获取我单击的饼图切片的值? Index/label/whatever??

要获取对单击的饼图切片的引用,您需要改用 dataPointSelection 函数。这允许您以您尝试过的方式获得 config.seriesIndexconfig.dataPointIndex

options: {
          chart: {
            events: {
              dataPointSelection:
                  (event, chartContext, config) => {
                    console.log('seriesIndex', config.seriesIndex);
                    console.log('dataPointIndex', config.dataPointIndex);
                  }
            },
          },
},

click 函数在用户单击图表上的任意位置时触发,并且不打算用于提取有关用户与特定数据点交互的数据。