import React from 'react'
import ReactApexChart from 'react-apexcharts'
import './styles.css'
// This demo also loads: https://cdn.jsdelivr.net/npm/apexcharts/dist/unit-shapes.js
const ApexChart = () => {
const [state, setState] = React.useState({
series: [3100, 1600, 800, 400, 300],
options: {
chart: {
type: 'unit',
height: 470,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['5 star', '4 star', '3 star', '2 star', '1 star'],
colors: ['#00A96E', '#7CB342', '#FFAB00', '#F2994A', '#FF4560'],
plotOptions: {
unit: {
layout: 'custom',
// One of the shapes in apexcharts/unit-shapes.
positions: 'star',
transition: 'flow',
unitValue: 8,
clusterLabels: {
// Outer labels: each band is named in the margin with a leader line to its
// own dots, so the crowd reads without a legend.
external: {
show: true,
},
},
},
},
legend: {
show: false,
},
},
})
return (
<div>
<div className="wrap">
<h1>6,200 reviews, one dot per 8</h1>
<p>
Ratings are ordered, so the palette climbs with them rather than
picking five unrelated hues. It still turns hue as it goes: five tints
of one colour would be close to indistinguishable at this dot size.
</p>
<div className="chart-wrap">
<div id="chart">
<ReactApexChart
options={state.options}
series={state.series}
type="unit"
height={470}
/>
</div>
</div>
<p className="note">1 dot = 8 reviews</p>
</div>
</div>
)
}
export default ApexChart