1

Highcharts Event with TypeScript

I am using custom events in my Highcharts together with the React wrapper. As an example it toggles the legend when opening and closing the full screen.

const options: Highcharts.Options = {
  chart: {
    events: {
      fullscreenOpen: function (this: any) {
        this.update({
          legend: {
            enabled: true,
          },
        });
      },
      fullscreenClose: function (this: any) {
        this.update({
          legend: {
            enabled: false,
          },
        });
      },
    },
  },
};

Correct typing?

How can I type the event correctly and can get rid of the this: any?

Code & Demo

Stackblitz Code

Stackblitz Demo

1

1 Answer 1

1

You can check types in Highcharts API. In your case it will be:

  chart: {
    events: {
      fullscreenOpen: function (this: Highcharts.Chart) {
        this.update({
          legend: {
            enabled: true
          }
        });
      },
      fullscreenClose: function (this: Highcharts.Chart) {
        this.update({
          legend: {
            enabled: false
          }
        });
      },
    },
  }

Live demo: https://stackblitz.com/edit/react-starter-typescript-nv7acw?file=App.tsx

API Reference:

https://api.highcharts.com/highcharts/chart.events.fullscreenOpen

https://api.highcharts.com/class-reference/Highcharts#.FullScreenfullscreenOpenCallbackFunction

Sign up to request clarification or add additional context in comments.

Comments

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.