Tooltip and custom label
Hi,
I would like to add custom label above group bars along with custom tooltip. Can this be done? Any examples would be appreciated.
Thank you.
Hi @ksavic, this should be documented in the Victory docs. If you have further questions, please check to see if there are duplicate discussions, and then open a Q&A discussion thread. Thanks!
Label usage and tooltip usage are documented but using both label and tooltip in same chart is not documented. There is some old instructions here for class based components but they don't work any more: https://github.com/FormidableLabs/victory/issues/551
Yea we need a modern, updated approach for doing this, with Typescript examples. Having a hell of a time getting the example working passing props to the components that are typed differently.
I was able to get around this by creating two nearly identical charts (pie charts in my case), one with a label, and one with a tool tip.
The pie chart with the tool tip was given transparent fill for each of the slices, and the pie chart with the label was given actual colors.
Then I positioned the pie chart with the tool tips absolutely over the pie chart with the labels.
Super hacky, but it gets the job done.
how do you make the slices have a transparent fill? @TeddyBurnsides
how do you make the slices have a transparent fill? @TeddyBurnsides
Here's what I did:
<VictoryPie
padding={{ top: 0, bottom: 0, left: 60, right: 60 }}
labelComponent={
<VictoryTooltip
constrainToVisibleArea
cornerRadius={3}
flyoutPadding={{ top: 4, bottom: 4, left: 10, right: 10 }}
flyoutStyle={{
stroke: "rgba(0,0,0,.4)",
fill: "rgba(255,255,255,.9)",
}}
/>
}
colorScale={["transparent"]}
data={series}
style={{
labels: {
fontFamily: "Inter",
fontSize: "10",
},
}}
/>
how do you make the slices have a transparent fill? @TeddyBurnsides
Here's what I did:
<VictoryPie
padding={{ top: 0, bottom: 0, left: 60, right: 60 }}
labelComponent={
<VictoryTooltip
constrainToVisibleArea
cornerRadius={3}
flyoutPadding={{ top: 4, bottom: 4, left: 10, right: 10 }}
flyoutStyle={{
stroke: "rgba(0,0,0,.4)",
fill: "rgba(255,255,255,.9)",
}}
/>
}
colorScale={["transparent"]}
data={series}
style={{
labels: {
fontFamily: "Inter",
fontSize: "10",
},
}}
/>