vue.js - 单击事件不适用于 ApexCharts (Vue3)

标签 vue.js vuejs3 apexcharts

每当有人点击我的图表或其中一个条形时,我都需要触发一个事件,但由于某些原因,事件不会为我触发。
这是我的代码:

<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 事件,但没有效果。
除了事件之外,我的图表显示和工作得很好。

最佳答案

我也为此苦苦挣扎,直到我找到了一些可行的方法。您可以使用 @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)
    },

关于vue.js - 单击事件不适用于 ApexCharts (Vue3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67329343/

相关文章:

javascript - Vue 路由器 : hide parent template when child is open

vue.js - Vuejs - 路由器 child

vue.js - Vue 3 - 全局 axios 实例

javascript - Vue watch 意外调用了两次

vue.js - Vue中如何加载外部CSS

javascript - 仅当内容与特定值匹配时才渲染 VUE 槽

javascript - 如何从 Composition API 中的 Axios Response 返回变量到根级别?

javascript - 如何从 ApexCharts 获取 URI 以下载 PDF 格式?

javascript - ApexCharts - 在 "Simple Donut Chart"中添加一个数字

vue.js - 构建后 Nuxt 插件不起作用(使用 apexchart )