如何将功能/方法而不是Chartjs中的整个图表添加到栏中?

我正在使用angular 8和chart.js并尝试在单击条形时添加功能,但是我所得到的只是在图形内部而不是条形图上单击。我是棱角新手,找不到任何示例。有人可以帮我添加哪个部分,以便可以单击其中一个栏并调用函数吗?谢谢 我的html就是这样

<canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions"
            [legend]="barChartLegend" [chartType]="barChartType" (click)="test()">
        </canvas>

.ts文件中的相关部分是这样的:

 public barChartOptions = {
    scaleShowVerticalLines: false,responsive: true,scales: {
      xAxes: [{
        scaleLabel: {
          display: true,labelString: 'X',},// onClick: function () {
        //   console.log("success");
        // }
      }],yAxes: [{
        scaleLabel: {
          display: true,labelString: 'Days',}
      }]
    },maintainAspectRatio: false,};
  test() {
    if (this.text == "worked") {
      this.text = "fail";
    } else {
      this.text = "worked";
    }
  }

  text = "fail";
  public barChartLabels = this.date;
  public barChartType = 'horizontalBar';
  public barChartLegend = true;
  public barChartData = [
    {
      data: this.temp,label: 'Temperature',}
  ];

昨晚,我刚刚发现可以监视单击事件的位置,并可以从单击的栏中获取数据。

onClick: (evt,array) => { //function
}
```I am wondering if there is an easier way to achieve this?
linlie17533 回答:如何将功能/方法而不是Chartjs中的整个图表添加到栏中?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168509.html

大家都在问