-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: grouped bar chart (aka stacked primary axis)
- Loading branch information
1 parent
f067ca5
commit fe65461
Showing
10 changed files
with
195 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import ResizableBox from "../ResizableBox"; | ||
import useDemoConfig from "../useDemoConfig"; | ||
import React from "react"; | ||
import { AxisOptions, Chart } from "react-charts"; | ||
|
||
export default function BarHorizontalStacked() { | ||
const { data, randomizeData } = useDemoConfig({ | ||
series: 10, | ||
dataType: "ordinal", | ||
}); | ||
|
||
const primaryAxis = React.useMemo< | ||
AxisOptions<typeof data[number]["data"][number]> | ||
>( | ||
() => ({ | ||
position: "left", | ||
getValue: (datum) => datum.primary, | ||
}), | ||
[] | ||
); | ||
|
||
const secondaryAxes = React.useMemo< | ||
AxisOptions<typeof data[number]["data"][number]>[] | ||
>( | ||
() => [ | ||
{ | ||
position: "bottom", | ||
getValue: (datum) => datum.secondary, | ||
stacked: true, | ||
}, | ||
], | ||
[] | ||
); | ||
|
||
return ( | ||
<> | ||
<button onClick={randomizeData}>Randomize Data</button> | ||
<br /> | ||
<br /> | ||
<ResizableBox> | ||
<Chart | ||
options={{ | ||
data, | ||
primaryAxis, | ||
secondaryAxes, | ||
}} | ||
/> | ||
</ResizableBox> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import ResizableBox from "../ResizableBox"; | ||
import useDemoConfig from "../useDemoConfig"; | ||
import React from "react"; | ||
import { AxisOptions, Chart } from "react-charts"; | ||
|
||
export default function BarStacked() { | ||
const { data, randomizeData } = useDemoConfig({ | ||
series: 10, | ||
dataType: "ordinal", | ||
}); | ||
|
||
const primaryAxis = React.useMemo< | ||
AxisOptions<typeof data[number]["data"][number]> | ||
>( | ||
() => ({ | ||
getValue: (datum) => datum.primary, | ||
}), | ||
[] | ||
); | ||
|
||
const secondaryAxes = React.useMemo< | ||
AxisOptions<typeof data[number]["data"][number]>[] | ||
>( | ||
() => [ | ||
{ | ||
getValue: (datum) => datum.secondary, | ||
stacked: true, | ||
}, | ||
], | ||
[] | ||
); | ||
|
||
return ( | ||
<> | ||
<button onClick={randomizeData}>Randomize Data</button> | ||
<br /> | ||
<br /> | ||
<ResizableBox> | ||
<Chart | ||
options={{ | ||
data, | ||
primaryAxis, | ||
secondaryAxes, | ||
}} | ||
/> | ||
</ResizableBox> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
fe65461
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: