How to highlight barchart when user onPress the chart in react-native

790 Views Asked by At

Is this possible using the onPress event can change the bar chart's particular bars colour or styles?

https://github.com/JesperLekland/react-native-svg-charts

Anybody, please help me.

1

There are 1 best solutions below

1
On

You should try to put the color or style in the state, and then in the onPress change it. And then the changes will be reflected:

onPress={()=> this.setState({colors: ['#7b4173', '#a55194', '#ce6dbd', '#de9ed6']})

And in the StackedBarChart, for Example, insert as a prop:

  <StackedBarChart
            style={{ height: 200 }}
            keys={keys}
            colors={this.state.colors}
            data={data}
            showGrid={false}
            contentInset={{ top: 30, bottom: 30 }}
        />