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: [28800, 8400, 2100, 1700],
options: {
chart: {
type: 'unit',
height: 470,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['Oak', 'Silver birch', 'Rowan', 'Wild cherry'],
// Green where the canopy is dense, then earth tones for the smaller species:
// four greens would be a single unreadable mass at this dot size, while green
// plus ochre plus bark keeps the tree looking like a tree.
colors: ['#2E7D32', '#7CB342', '#C9A227', '#8D6E63'],
plotOptions: {
unit: {
layout: 'custom',
// One of the shapes in apexcharts/unit-shapes.
positions: 'tree',
transition: 'flow',
unitValue: 50,
clusterLabels: {
external: {
show: true,
},
},
},
},
legend: {
show: false,
},
},
})
return (
<div>
<div className="wrap">
<h1>41,000 saplings, one dot per 50</h1>
<p>
A lobed canopy over a flared trunk, packed with dots. The outline is
two overlapping subpaths, which the layout unions before it packs, so
a canopy with nine bumps and a trunk with roots is one shape rather
than a circle balanced on a rectangle.
</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 = 50 saplings planted this season</p>
</div>
</div>
)
}
export default ApexChart