codenamezero
Posts: 22
Joined: Thu Dec 19, 2019 7:23 pm

How to addEvent on "options.chart" or "options.plotOptions.series.point" etc?

How to addEvent on "options.chart" or "options.plotOptions.series.point" etc?

Stuff read:
https://github.com/highcharts/highchart ... issues/112
https://stackoverflow.com/a/59425869/1009046

I can't seem to be able to get `addEvent` to work.

I tried to do something like this:

Code: Select all

  import { addEvent } from 'highcharts';
  ...
  addEvent(options.plotOptions.series.point.events, 'click', (evtObject: PointClickEventObject) => {
    console.log('WASDWASD');
  });
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: How to addEvent on "options.chart" or "options.plotOptions.series.point" etc?

Hello codenamezero,

Thanks for contacting us with your question.

addEvent is a native Highcharts method. In some cases it won't be possible to assign a specific event to an element. However, adding click event to single point, or even whole series is possible.
Demo: https://jsfiddle.net/BlackLabel/pso08yx7/

Let me know if that was what you were looking for!
Best regards!
Mateusz Bernacik
Highcharts Developer
codenamezero
Posts: 22
Joined: Thu Dec 19, 2019 7:23 pm

Re: How to addEvent on "options.chart" or "options.plotOptions.series.point" etc?

Is there no easier way to add it to all the series/points rather than programmatically go through every series/points to add them? If I replace the data/series in the chart, don't I need to run the code to re-add them all over again...?
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: How to addEvent on "options.chart" or "options.plotOptions.series.point" etc?

Hello codenamezero,

It really depends. For this specific case presented in the demo you can simply use either plotOptions.series.events.click or series.line.data.events.click events to achieve exactly the same results. You should only consider using Highcharts.addEvent method in cases, where an event is not supported from API level. I have shown you the usage because you asked about it. If you're looking for specific event then check thoroughly our API docs or feel free to ask.

API reference: https://api.highcharts.com/highcharts/p ... ents.click
https://api.highcharts.com/highcharts/s ... ents.click

Let me know if you have any further questions!
Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”