SetPointerIndex #1091
-
|
i have searched the github reported issues and documentation as well and find out the initialPointerIndex but even that does not show the tooltip and also does not change the pointer index when different index assigned to intitalPointerIndex but i have a scenario i need to dynamically show the pointer strip with tooltip in multiline chart so when i press the legend item at top i need to show the pointer on that label (date) dynamically without user need to click on the chart. i think there should be setPointerIndex callback that can help in this case i am trying to fork the library but want to get help if there is some other way |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Hi @jaikantshikray I am not sure if it is currently achievable using pointers. But it can be done easily using focus. Here's an example- https://snack.expo.dev/@ak_97/focus-with-external-control?platform=android Focus.movThe code for the above chart is- import {useState} from 'react'
import { Text, View, Pressable, SafeAreaView, StyleSheet } from 'react-native';
import {LineChart} from 'react-native-gifted-charts'
export default function App() {
const [index,setIndex] = useState(-1)
const data = [{value:10},{value:14},{value:16},{value:9},{value:12},]
return (
<SafeAreaView style={styles.container}>
<LineChart
data={data}
focusEnabled
showStripOnFocus
focusedDataPointLabelComponent={(item)=>(<View style={styles.button}><Text>{item.value}</Text></View>)}
focusedDataPointIndex={index}
/>
<Text>Press a day to select:</Text>
<View style={styles.row}>
<Pressable onPress={()=>setIndex(0)} style={styles.button}>
<Text>{'Sun'}</Text>
</Pressable>
<Pressable onPress={()=>setIndex(1)} style={styles.button}>
<Text>{'Mon'}</Text>
</Pressable>
<Pressable onPress={()=>setIndex(2)} style={styles.button}>
<Text>{'Tue'}</Text>
</Pressable>
<Pressable onPress={()=>setIndex(3)} style={styles.button}>
<Text>{'Wed'}</Text>
</Pressable>
<Pressable onPress={()=>setIndex(4)} style={styles.button}>
<Text>{'Thu'}</Text>
</Pressable>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
button:{backgroundColor:'lightgreen', padding:6, width:44},
row:{flexDirection:'row', justifyContent:'space-between',marginTop:20}
}); |
Beta Was this translation helpful? Give feedback.
-
|
Yes, @jaikantshikray It will work for multi-line charts, and also you can trigger focus on Bar and Line charts together. here's an example- https://snack.expo.dev/@ak_97/focus-with-external-control-multiline?platform=android focusTogether.movThe only problem is that each line in the line chart has its own separate tooltip. But you want one single tooltip displaying values of all lines. This is perhaps not achievable if focus is triggered by an external component as is the case here. But, if the focus is triggered by pressing an area inside the chart, then we can use the prop Feel free to raise a PR with this enhancement- single tooltip (or |
Beta Was this translation helpful? Give feedback.
Hi @jaikantshikray I am not sure if it is currently achievable using pointers. But it can be done easily using focus.
Here's an example- https://snack.expo.dev/@ak_97/focus-with-external-control?platform=android
Focus.mov
The code for the above chart is-