Open fredlemieux opened 6 years ago
Looking at the CustomGridExample in the storybook examples helped me resolve this:
// Vertical grid
data.map((_, index) => (
<Line
key={ index }
y1={ '0%' }
y2={ '100%' }
x1={ x(index) }
x2={ x(index) }
stroke={ 'rgba(0,0,0,0.2)' }
/>
))
Notice x1
& x2
are set to x(index)
and not x(tick)
. This might be something we could fix in the Grid component itself but I'm not sure how that would affect using it with other components.
Were you able to resolve this? Doing x1={ x(index) } x2={ x(index) }
is not working for me because x(index)
returns very low numbers (e.g., -7240355.0000433875).
My dataset looks similar to yours. I have an array of items with date (as the xAccessor) and value (yAccessor).
It seems from my experimenting that the xAccessor isn't passed down to the child (the Grid). So if you use x(value), the value isn't correct - it's not the date. I don't know if that's deliberate, or a bug. This solution works for me:
// Vertical grid data.map((value, index) => ( <Line key={index} y1={'0%'} y2={'100%'} x1={x( data[ index ].date )} x2={x( data[ index ].date )} stroke={'red'} /> ))
I did the same but not working for me. Can't get decorators to work on the time series either.
I did the same but not working for me. Can't get decorators to work on the time series either.
Did you see my solution above for the vertical grid? I've been able to get decorators working the same way. If you want to share your code I'll be happy to help you figure it out.
got it working thanks. My issue was a combination of this and I actually had a conflicting component called Line to draw the custom Path haha.
What is the problem?
This is probably a lack of understanding from my side rather than an issue with "react-native-svg-charts", but perhaps others are having a similar issue and it'll be worth having the solution here. I can't get vertical gridlines to display correctly when using time series data, the only vertical gridline shown is the Y-Axis of the chart.
There isn't much documentation on how the custom grid works, so it is hard to know where I'm going wrong with this. If I use the index (rather than value) of the data.map function in the custom grid I don't even get the vertical line in the Y-Axis. What am I doing wrong?
Platform
React Native version: "dependencies": { "axios": "^0.18.0", "expo": "^30.0.1", "react": "16.3.1", "react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz", "react-native-svg": "^7.0.2", "react-native-svg-charts": "^5.2.0", "react-navigation": "^2.14.2", }
Code below: