1

我正在使用 react-highcharts 并且试图找到一种在单击 Y 轴类别之一时触发事件的方法。我正在使用 xrange 图表。我想获取单击的值的偏移量。例如,如果我有:

CatA

Catb

CatC

如果我点击 CatB,我将得到 1。

我找到了一个 jquery 解决方案,它本身就给了我价值。获取所有元素并遍历它们并自己找到偏移量并不是问题。jquery的解决方法:

$("#container .highcharts-yaxis-labels text").click(function() {
            alert($(this).text());
        });

我正在为此寻找 react/react-highcarts 解决方案。

更新

谢谢卡米尔库利格!我在图书馆遇到了麻烦。我将库导入为

import HighchartsCustomEvents from 'highcharts-custom-events';

什么也没发生,我也在 componentWillMount 函数中添加了这段代码:

template.yAxis.events.click = function () {
            alert(1);
        };

我看到了文档,但没有找到任何偏移函数,这意味着我还是使用 jquery 吗?或者你有什么想法吗?

4

1 回答 1

1

Highcharts 提供 了能够处理您需要的操作的自定义事件模块。

npm 上的模块参考: https ://www.npmjs.com/package/highcharts-custom-events

Highcharts 网站上的模块参考: https ://www.highcharts.com/products/plugin-registry/single/15/Custom-Events

示例代码:

    yAxis: {
        labels: {
            events: {
                click: function () {
                   // do something
                }
            }
        }
    }
于 2018-04-25T09:58:09.037 回答