繁体   English   中英

如何禁用图表 ChartJS 中的点击

[英]How to disable click in graph ChartJS

我有以下代码在 ChartJS 中呈现我的图表:

public renderCanvas() {
this.canvas = document.getElementById('myChart');
this.ctx = this.canvas.getContext('2d');

const gradient = this.ctx.createLinearGradient(10, 0, 120, 0);
gradient.addColorStop(0, '#429321');
gradient.addColorStop(1, '#B4EC51');

const myChart = new Chart(this.ctx, {
  type: 'doughnut',
  options: { cutoutPercentage: 85, rotation: 2.72, circumference: 4, aspectRatio: 2.8, legend: { display: false }, onClick: null },
  data: {
    labels: ['clients.', 'no clients.'],
    datasets: [{ data: [this.segurosClients, this.prosperaClients], backgroundColor: [gradient, '#E3E7F3'], borderWidth: 1 }],
  },
});

但是当我点击时,它会打开这个弹出窗口,我希望它被禁用

您设置为nullonClick属性似乎没有任何作用。

根据文档,您可以使用optionsevents属性控制图表侦听哪些事件。 例如,如果您希望图表侦听除click之外的所有事件, click尝试以下操作:

const myChart = new Chart(this.ctx, {
  type: 'doughnut',
  options: { 
      cutoutPercentage: 85, 
      rotation: 2.72, 
      circumference: 4, 
      aspectRatio: 2.8, 
      legend: { 
          display: false 
      },
      events: ['mousemove', 'mouseout', 'touchstart', 'touchmove'],
  data: {
    labels: ['clients.', 'no clients.'],
    datasets: [{ data: [this.segurosClients, this.prosperaClients], backgroundColor: [gradient, '#E3E7F3'], borderWidth: 1 }],
  },
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM