首页 > 解决方案 > 如何在 angular-flot 条上添加 onclick 功能

问题描述

我使用 angular-flot 创建一些数据的字符表示,这是我的 .html :

<div  flot  id="dataChar" [dataset]="barData" [options]="barOptions" height="300"></div>

然后在我的 .ts 中,我通过添加选项来配置 flot:

    barData: any;
      barOptions = {
        series: {
          bars: {
            align: 'center',
            lineWidth: 0,
            show: true,
            barWidth: 0.6,
            fill: 0.9
          }
        },
        grid: {
          borderColor: '#eee',
          borderWidth: 1,
          hoverable: true,
          backgroundColor: '#fcfcfc',
          clickable:true
        },
        tooltip: true,
        tooltipOpts: {
          content: function (label, x, y) { return x + ' : ' + y; }
        },
        xaxis: {
          tickColor: '#fcfcfc',
          mode: 'categories'
        },
        yaxis: {
          tickColor: '#eee'
        },
        shadowSize: 0
      };

我已经看到在 ChartJs 中你可以使用onClick,我尝试在这里使用它但它不起作用,那么我该如何在这里添加事件呢?我一直在搜索的所有内容似乎都在 jquery 中,我不知道我是否可以在我的项目中使用它,所以任何帮助都将不胜感激

标签: javascriptangularflot

解决方案


你能检查一下“actions”数组吗?我认为您需要为元素定义操作。'handler(chart)' 是一种添加处理程序的方法。检查这篇文章。

ChartJs 浮动条


推荐阅读