【问题标题】:Click event not working with ApexCharts (Vue3)单击事件不适用于 ApexCharts (Vue3)
【发布时间】:2021-07-23 12:40:57
【问题描述】:

每当有人点击我的图表或其中一个条时,我都需要触发一个事件,但由于某种原因,我不会触发事件。

这是我的代码:

<apexchart type="rangeBar" :options="chartOptions" class="ganttChart" :series="series"></apexchart>

还有我的设置:

setup() {
 const series = [
            {
              name: 'Sunny',
              data: [
                {
                  x: 'Weather',
                  y: [
                    new Date('2019-03-05').getTime(),
                    new Date('2019-03-08').getTime()
                  ]
                },
              ]
            },
            {
              name: 'Rainy',
              data: [
                {
                  x: 'Weather',
                  y: [
                    new Date('2019-03-02').getTime(),
                    new Date('2019-03-05').getTime()
                  ]
                },
              ]
            }
          ];

  const chartOptions = {
            chart: {
                events: {
                    click: function(event, chartContext, config) {
                        alert(event, chartContext, config);
                    }
                },
              height: 400,
              width: 400,
              type: 'rangeBar',
              
            },
            plotOptions: {
              bar: {
                horizontal: true
              }
            },
            
            fill: {
              type: 'gradient',
              gradient: {
                shade: 'light',
                type: 'vertical',
                shadeIntensity: 0.25,
                gradientToColors: undefined,
                inverseColors: true,
                opacityFrom: 1,
                opacityTo: 1,
                stops: [50, 0, 100, 100]
              }
            },
            xaxis: {
              type: 'datetime'
            },
            legend: {
              position: 'top'
            }
          };

         return { 
              series, chartOptions 
              }
    }

我也尝试过使用 dataPointSelection 事件,但没有效果。

除了事件,我的图表显示和工作都很好。

【问题讨论】:

  • 相同 - 我们无法在此库中触发任何事件

标签: vue.js vuejs3 apexcharts


【解决方案1】:

我也为此苦苦挣扎,直到我找到了可行的方法。你可以像这样使用@click

<apexchart type="rangeBar" :options="chartOptions" class="ganttChart" :series="series" @click="clickHandler"></apexchart>

然后在你的方法中定义clickHandler

methods: {
    clickHandler(event, chartContext, config){
        console.log("click")
        console.log(event)
        console.log(chartContext)
        console.log(config)
    },

【讨论】:

  • 工作正常,其他图表事件@dataPointSelection="handleDirectionSelection"也工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-12
  • 1970-01-01
相关资源
最近更新 更多