reflex icon indicating copy to clipboard operation
reflex copied to clipboard

How to add a custom tooltip to Recharts components?

Open nogaini opened this issue 1 year ago β€’ 2 comments

I have a CustomTooltip local component stored in assets/customtooltip.js. How can I include this tooltip inside a recharts component?

I tried this:

class CustomTooltip(rx.Component):
    library = "/public/customtooltip"

rx.recharts.line_chart(
                        rx.recharts.x_axis(data_key="name"),
                        rx.recharts.y_axis(),
                        CustomTooltip(),
                        rx.recharts.legend(),
                        data=State.data,
                    ) 

But this gives me the error:

ValueError: The component `LineChart` only allows the components: `XAxis`, `YAxis`, `ReferenceArea`, `ReferenceDot`, `ReferenceLine`, `Brush`, `CartesianGrid`, `Legend`, `GraphingTooltip`, `Line` as children. Got `CustomTooltip` instead.

nogaini avatar Jun 14 '24 11:06 nogaini

Try using GraphingTooltip instead of CustomToolTip

Manas1820 avatar Jul 12 '24 08:07 Manas1820

@Manas1820 The point is to use a custom tooltip for displaying stuff not currently possible with GraphingTooltip. :)

nogaini avatar Jul 12 '24 08:07 nogaini

In this regard, passing the "formatter" parameter of GraphingTooltip would be amazing.

E.g., using formatter="{(value) => value && value.toLocaleString()}" or formatter="new Intl.NumberFormat('de-DE').format(value)"

I've tried both to no avail.

latze123 avatar Oct 18 '24 17:10 latze123