0

Seeing the below error when trying to render a lollipop chart in react using the highcharts-react-official module. If I change the series type to line it renders fine
ReferenceError: Highcharts is not defined

Example Code:

import Highcharts, {Options} from 'highcharts'
import HighchartsReact from 'highcharts-react-official'

const options: Options = {
  chart: {
    type: 'lollipop'
  },
  series: [{
    name: 'Example Series',
    type: 'lollipop',
    data: [10, 20, 50, 30, 100]
  }]
}

const ExampleComponent = () => (
  <HighchartsReact
    highcharts={Highcharts}
    options={options}
  />
)

3 Answers 3

0

Remember to load the necessary modules correctly: https://github.com/highcharts/highcharts-react#how-to-add-a-module

You can find a simple demo here: https://stackblitz.com/edit/react-hnwmgd?file=index.js

import React from "react";
import { render } from "react-dom";
// Import Highcharts
import Highcharts from "highcharts/highstock";
import HighchartsReact from "highcharts-react-official";
import HC_more from "highcharts/highcharts-more";
import highchartsDumbbell from "highcharts/modules/dumbbell";
import highchartsLollipop from "highcharts/modules/lollipop";

// init the module
highchartsDumbbell(Highcharts);
highchartsLollipop(Highcharts);
HC_more(Highcharts);
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using Typescript, the initialization should be done directly in the React component.

If you initialize the module outside the component, you might encounter a TypeError after updating your app.

import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";
import HighChartsMore from "highcharts/highcharts-more";
import dumbbell from "highcharts/modules/dumbbell";
import lollipop from "highcharts/modules/lollipop";

const options = {...};

const ExampleComponent = () => {
    // module initialization
    HighChartsMore(Highcharts);
    dumbbell(Highcharts);
    lollipop(Highcharts);

    
    return <HighchartsReact highcharts={Highcharts} options={options} />;
}

Comments

0

Let me just add that you need to import both the dumbbell and the lollipop series if you want to use lollipop, and that the imports HAVE TO BE in that order:

HighchartsDumbbell(Highcharts);
HighchartsLollipop(Highcharts);

and not:

HighchartsLollipop(Highcharts);
HighchartsDumbbell(Highcharts);

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.