javascript - 如何禁用图表 ChartJS 中的点击

标签 javascript angular typescript ionic-framework chart.js

我有以下代码在 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 属性似乎没有执行任何操作。

根据documentation ,您可以使用 options 中的 events 属性控制图表监听哪些事件。例如,如果您希望图表监听除 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 }],
  },
});

关于javascript - 如何禁用图表 ChartJS 中的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59158338/

相关文章:

javascript - 如何在 GreaseMonkey 中点击

angular - TypeError : this. router.events.filter is not a function error whichi uploading angular app to Aws s3 bucket

typescript - ts ES5/ES3 中的异步函数或方法需要 'Promise' 构造函数

javascript - 为 Coin 货币市场实现 highcharts

javascript - 转.js : Responsive Design With a Double-Page Viewing Format Not Working

angular - 复制对象的值而不绑定(bind)它们

angular - "Error: No provider for Overlay!"

angular - 如何定义 Angular 内部服务并使其不可注入(inject)到其模块之外?

angular - Typescript 上的 IsNan

javascript - 使用复选框在 Google Fusion Tables 中进行过滤