【问题标题】:How to call a function inside the Apexcharts Events with angular component?如何使用角度组件调用 Apexcharts 事件中的函数?
【发布时间】:2021-05-07 10:16:40
【问题描述】:

我正在使用 apexcharts 角度库来图形表示我的数据。当我单击该栏时,我想触发另一个功能。这是我的条形图配置。

this.chartOptions = {
      series: [
        {
          name: "basic",
          data:[25,30,35,40]
        }
      ],
      chart: {
        type: "bar",
        height: 350,
        
        events: {
          click(event, chartContext, config) {
            console.log(config.seriesIndex);
            console.log(config.dataPointIndex);
            //this.getStates(config.dataPointIndex);
            var test: number = config.dataPointIndex;
            console.log(config.globals.labels[test]);
            this.getStates(test);
          }
        }
      },
      plotOptions: {
        bar: {
          horizontal: true
        }
      },
      dataLabels: {
        enabled: false
      },
      xaxis: {
        categories: ["India","Pakistan","USA","England"]
      }
    }

这里,getStates 是我希望在单击图表中的任何条时触发的函数。

有人可以回答如何调用该函数吗?

【问题讨论】:

    标签: angular apexcharts


    【解决方案1】:

    你可以传入一个箭头函数作为回调函数来保留this关键字的含义。

    chart: {
      type: "bar",
      height: 350,
      events: {
        click: (event: any, chartContext: any, config: any) => {
          this.getStates(config.dataPointIndex);
    
          console.log(config.seriesIndex);
          console.log(config.dataPointIndex);
          var test: number = config.dataPointIndex;
          console.log(config.globals.labels[test]);
          this.getStates(test);
        }
      }
    }
    

    您可以在回调here 中找到更多关于this 关键字含义的信息。

    【讨论】:

      猜你喜欢
      • 2016-07-18
      • 2020-09-05
      • 2021-04-17
      • 2020-05-22
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      相关资源
      最近更新 更多