react-native-chart-kit icon indicating copy to clipboard operation
react-native-chart-kit copied to clipboard

How to add tooltip?

Open evertoont opened this issue 3 years ago • 13 comments

Is it possible to add tooltip when clicking on the graph dots?

Example: image

evertoont avatar Mar 16 '22 21:03 evertoont

+1

yyskyrr avatar Mar 22 '22 08:03 yyskyrr

+1

AhmetToma avatar Mar 29 '22 00:03 AhmetToma

+1

arieldamian avatar Jul 23 '22 02:07 arieldamian

+1

matextrem avatar Jul 23 '22 02:07 matextrem

Is there any solution

rvenky125 avatar Aug 01 '22 12:08 rvenky125

+2

alexjs87 avatar Aug 22 '22 18:08 alexjs87

+1

ElliotWood13 avatar Oct 26 '22 12:10 ElliotWood13

is there any solution for this?? thanks in advance

AmitP1392 avatar Nov 03 '22 08:11 AmitP1392

@Hermanya any update on this ? thanks

Ahmed-Imam3 avatar Dec 07 '22 11:12 Ahmed-Imam3

you can use this method in the line chart. use onDataPointClick update the point data to your state and then show the tooltip based on indexData in renderDotContent

renderDotContent={({x, y, index, indexData}) => { if ( indexDataState === indexData) { // show tooltip return ( <CustomDot x={x} y={y} /> ); } return null; }}

ShahoodHussain77 avatar Dec 07 '22 16:12 ShahoodHussain77

you can use this method in the line chart. use onDataPointClick update the point data to your state and then show the tooltip based on indexData in renderDotContent

renderDotContent={({x, y, index, indexData}) => { if ( indexDataState === indexData) { // show tooltip return ( ); } return null; }}

@ShahoodHussain77 Thanks, this works! Should be in the docs.

jameskim917 avatar Feb 08 '23 07:02 jameskim917

import {LineChart} from 'react-native-chart-kit'; import {Rect, Text as TextSVG, Svg} from 'react-native-svg';

let [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0, visible: false, value: 0, });

<LineChart ....... decorator={() => { return tooltipPos.visible ? ( <View> <Svg> <Rect x={tooltipPos.x - 15} y={tooltipPos.y + 10} width="40" height="30" fill="white" /> <TextSVG x={tooltipPos.x + 5} y={tooltipPos.y + 30} fill="black" fontSize="16" fontWeight="bold" textAnchor="middle"> {tooltipPos.value} </TextSVG> </Svg> </View> ) : null; }} onDataPointClick={data => { let isSamePoint = tooltipPos.x === data.x && tooltipPos.y === data.y; isSamePoint ? setTooltipPos(previousState => { return { ...previousState, value: data.value, visible: !previousState.visible, }; }) : setTooltipPos({ x: data.x, value: data.value, y: data.y, visible: true, }); }} />

Screenshot 2023-04-17 at 6 38 53 PM

ziaRJ avatar Apr 17 '23 13:04 ziaRJ