Skip to content

Instantly share code, notes, and snippets.

@destpat
Created October 16, 2020 16:59
Show Gist options
  • Save destpat/aad290594f038a56497b4e44b25c7d11 to your computer and use it in GitHub Desktop.
Save destpat/aad290594f038a56497b4e44b25c7d11 to your computer and use it in GitHub Desktop.
Create custom legend buttons for React Highcharts stacked bar chart component
import React, { useState } from 'react';
import { Box, Checkbox, FormControlLabel, FormGroup } from '@material-ui/core';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import configObj from '../utils/configObj';
export const StackedBarChart = () => {
const [scopeButton, setScopeButton] = useState(<div />);
const highchartsCallback = chart => {
chart.series.forEach((item, index) => {
return (
<FormControlLabel
key={index}
control={
<Checkbox
defaultChecked={true}
onChange={() => item.setVisible(!item.visible)}
name={item.name}
color="primary"
/>
}
label={item.name}
/>
);
});
};
return (
<div>
<HighchartsReact highcharts={Highcharts} options={configObj} callback={highchartsCallback} />;
<FormGroup row>{scopeButton}</FormGroup>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment