-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleBarChart.tsx
44 lines (40 loc) · 1.09 KB
/
SimpleBarChart.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { BarChart } from "@mui/x-charts";
import { data } from "../../data";
import { Type, Static } from "@sinclair/typebox";
import { labelSchema } from "../../labels";
export const slug = "bar";
export const jsonSchema = Type.Object(
{
type: Type.Literal(slug),
props: Type.Object(
{
labels: Type.Array(labelSchema, {
minItems: 1,
maxItems: 3,
title: "Bar Chart Labels",
description: "The labels to display on the bar chart",
}),
fullWidth: Type.Optional(
Type.Boolean({ title: "Should the chart occupy the full width?" }),
),
},
{
title: "Bar Chart Properties",
},
),
},
{
title: "Bar Chart",
description: "A simple bar chart",
},
);
type BarChartSchema = Static<typeof jsonSchema>;
export function Component({ labels, fullWidth }: BarChartSchema["props"]) {
return (
<BarChart
height={fullWidth ? 800 : 300}
series={labels.map((label) => ({ label, data: data[label] }))}
xAxis={[{ data: data.xLabels, scaleType: "band" }]}
/>
);
}