Bar Chart
packages
@mantine/charts
recharts
stylesheet
import "@mantine/charts/styles.css"
bar-chart logic
for each index, display one or several bars. We assume one bar for each index.
data for a given index
The chart library expects an object for each index. The object contains raw data. Among this data, we select which property acts as the label. The remaining properties may act as magnitude.
{month: "Jan", workouts: 17},
{month: "Feb", workouts: 18}
indicate data's shape
We indicate:
- the property that acts as the label, here month
- for each property that we want to act as a magnitude, we indicate: the property's name (here workouts) the color for that bar, and the label for that bar.
In the following example, workouts provides the magnitude for the unique serie.
<BarChart
data={}
h={300}
dataKey="month" // key that provides label
series={[
// bar(s) configuration
{ name: "workouts", color: "blue.6", label: "Workouts" },
]}
/>
Each magnitude's property, as it spreads over all the indexes, makes a distinct serie. For example, the ipadSales, the iponeSales, and the macSales make each one a distinct serie.