React-native-svg-charts: [Feature] Allow strings for XAxis data

Created on 7 Feb 2020  路  4Comments  路  Source: JesperLekland/react-native-svg-charts

Description of feature

The x-axis labels could be a list of strings, right? At least that's what I have.
But I'm getting a

Warning: Failed prop type: Invalid prop data[0] supplied to XAxis.

Because of XAxis.propTypes only allowing numbers and objects for the data array items.

If you agree, I'm willing to make a PR to fix this.

feature request

Most helpful comment

i am using formatLabel={index => data[index].yourValue} to call an item in the array

All 4 comments

Would love for this to be fixed so date strings can be easily fed into the Xaxis 馃憤

if you need anything else than numbers you can use the xAccessor and yAccessor to correctly map it to numerical data. If dates are to be used you need the correct xScale/ yScale

i am using formatLabel={index => data[index].yourValue} to call an item in the array

As JesperLekland mentioned, xAccessor also works well:

<XAxis
                  style={{marginHorizontal: -10, height: xAxisHeight}}
                  data={data}
                  xAccessor={({item}) => item.date}
                  formatLabel={value => moment(value).format("DD-MM-YYYY")}
                  contentInset={{left: 30, right: 30}}
                  svg={{
                    fontSize: 10,
                    fill: 'black',
                    fontWeight: 'bold',
                    rotation: 20,
                    originY: 15,
                    y: 15
                  }}
                />

https://i.imgur.com/ua6v54n.png

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mafiusu picture mafiusu  路  3Comments

themathiou picture themathiou  路  3Comments

rohithnair1996 picture rohithnair1996  路  3Comments

vjsingh picture vjsingh  路  6Comments

lotcz picture lotcz  路  3Comments