-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add horizontal stacked bar chart gallery example (#2807)
- Loading branch information
1 parent
a6ee1dd
commit 34071c5
Showing
1 changed file
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
id: 51 | ||
title: Horizontal Stacked Bars | ||
description: Horizontal Stacked Bars with Custom Tooltips | ||
--- | ||
|
||
```playground_norender | ||
const axisTickValues = [30, 100]; | ||
const data = [[{ x: 0, y: 29 }], [{ x: 0, y: 70 }], [{ x: 0, y: 30 }]]; | ||
const styles = [ | ||
{ data: { fill: "#f3d437", stroke: "#d1b322", strokeWidth: 1 } }, | ||
{ data: { fill: "#0ca340", stroke: "#0ca340", strokeWidth: 1 } }, | ||
{ data: { fill: "#f3d437", stroke: "#d1b322", strokeWidth: 1 } }, | ||
]; | ||
const labelFn = ({ datum }) => | ||
datum.y < axisTickValues[0] ? `${datum.y} Low` : `${datum.y} Normal`; | ||
class App extends React.Component { | ||
render() { | ||
return ( | ||
<div> | ||
<VictoryChart> | ||
<VictoryAxis | ||
dependentAxis | ||
tickValues={axisTickValues} | ||
style={{ | ||
tickLabels: { fontSize: 10, padding: 10 }, | ||
}} | ||
/> | ||
<VictoryStack style={{ data: { width: 10 } }} horizontal> | ||
{data.map((d, i) => ( | ||
<VictoryBar | ||
style={styles[i]} | ||
data={d} | ||
labels={i === 0 ? labelFn : undefined} | ||
labelComponent={ | ||
<VictoryTooltip | ||
active | ||
dy={-10} | ||
horizontal={false} | ||
flyoutStyle={{ | ||
fill: "#fbf2ca", | ||
stroke: "#ae9308", | ||
strokeWidth: 0.5, | ||
}} | ||
/> | ||
} | ||
/> | ||
))} | ||
</VictoryStack> | ||
</VictoryChart> | ||
</div> | ||
); | ||
} | ||
} | ||
ReactDOM.render(<App/>, mountNode); | ||
``` |