Search code examples
reactjshighchartspie-chartreact-highcharts

Using PieChart from highcharts-react-official


Is there a working example of using PieChart from highcharts-react-official [ https://www.npmjs.com/package/highcharts-react-official ]

There is mention of PieChart tag on the below link, but I couldn't find any working example for it: Setting Highcharts piechart chartDefaults from calling jsx file in React

There is one more working example at below link, but it doesn't use PieChart tag: https://codesandbox.io/s/ovx6kqokqq

Does anyone know of an example for PieChart tag?

Thanks.


Solution

  • You do not need to use PieChart tag to create a pie chart using highcharts-react-official. The type of chart or series in options is important, but the name of tag is not, so for example you can do it this way:

    ...
    
    import PieChart from "highcharts-react-official";
    
    const options = {
      chart: {
        type: "pie"
      },
      series: [...]
    };
    
    class App extends React.Component {
      ...
    
      render() {
        return (
          <div>
            <h2>Highcharts</h2>
            <PieChart highcharts={Highcharts} options={options} />
          </div>
        );
      }
    }
    

    Live demo: https://codesandbox.io/s/139x5p4qpq