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: [6200, 2400, 2000, 1000],
options: {
chart: {
type: 'unit',
height: 470,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['Solar farms', 'Rooftop solar', 'Wind', 'Hydro'],
colors: ['#FFAB00', '#F2994A', '#00A6A0', '#1565C0'],
plotOptions: {
unit: {
layout: 'custom',
// One of the shapes in apexcharts/unit-shapes.
positions: 'sun',
transition: 'flow',
unitValue: 20,
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>11,600 GWh of renewable electricity, one dot per 20</h1>
<p>
A sun built from its own data. The shape is a custom unit layout: a
function that receives every dot and the plot rect and returns
positions, so the rays are packed from the outline rather than drawn
behind the dots.
</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 = 20 GWh</p>
</div>
</div>
)
}
export default ApexChart