Implement Highcharts library in a React application

ashukasma

Aashish Kasma

Posted on March 2, 2023

Implement Highcharts library in a React application

Highcharts is a popular JavaScript library for creating interactive charts and graphs. Here's how you can use it in a React application:

  • Installing the Highcharts React Wrapper:

The first step is to install the Highcharts React wrapper, which allows you to use Highcharts in a React component. You can install it using npm by running the following command:

npm install highcharts-react-official

Enter fullscreen mode Exit fullscreen mode
  • Importing Highcharts and the Wrapper in Your Component:

Once you have installed the wrapper, you can import Highcharts and the Highcharts React wrapper in your component like this:

import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

Enter fullscreen mode Exit fullscreen mode
  • Creating a Simple Bar Chart:

Here's an example of how to create a simple bar chart in React using Highcharts:

import React, { useState } from 'react';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

function App() {
  const [options, setOptions] = useState({
    chart: {
      type: 'bar'
    },
    title: {
      text: 'Fruit Consumption'
    },
    xAxis: {
      categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
      title: {
        text: 'Fruit eaten'
      }
    },
    series: [
      {
        name: 'Jane',
        data: [1, 0, 4]
      },
      {
        name: 'John',
        data: [5, 7, 3]
      }
    ]
  });

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

export default App;
Enter fullscreen mode Exit fullscreen mode

You can also read more charts using High Charts

Implementing Highcharts library in a React application

I hope this will help you understand High Charts Library

💖 💪 🙅 🚩
ashukasma
Aashish Kasma

Posted on March 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024