1

I'm using react-highcharts and I'm trying to find a way to trigger an event when one of the Y-axis categories is being clicked. I'm using xrange graph.I want to get the offset of the value that was clicked. For example, if i have:

CatA

Catb

CatC

If I will click on CatB I will get 1.

I found a jquery solution, which give me the value itself. Its not a problem to get all the elements and iterate over them and found the offset myself. The solution of jquery:

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

I'm looking for react/react-highcarts solution for that.

Update

Thanks Kamil Kulig! Im getting trouble with the library. I import the library as

import HighchartsCustomEvents from 'highcharts-custom-events';

And nothing happned, also i added this code at componentWillMount function:

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

I saw the docs and I didnt find any offset function, which means that sould I use jquery anyway? or do u have any idea?

1
  • You can perform operations either on axis' labels (yAxis.labels.events) or axis' title (yAxis.title.events). yAxis.events won't work. Commented Apr 27, 2018 at 14:53

1 Answer 1

1

Highcharts offers the custom events module that is able to handle the actions that you require.

Module reference on npm: https://www.npmjs.com/package/highcharts-custom-events

Module reference on Highcharts website: https://www.highcharts.com/products/plugin-registry/single/15/Custom-Events

Sample code:

    yAxis: {
        labels: {
            events: {
                click: function () {
                   // do something
                }
            }
        }
    }
Sign up to request clarification or add additional context in comments.

3 Comments

I'm getting lost to combine it with react-highcharts module and es6, can you help?
I can help with the official wrapper for Highcharts (You're using a non official version). This doc explains how to import an extra module to Highcharts in React (by the example of Highmaps module): (npmjs.com/package/highcharts-react-official
Wow alot ofrreact-highcharts... I will check that right away. Any idea for getting the offset?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.