Skip to content

I want to show amounts on y axis in L, K and Cr format  #1009

@shaadescs

Description

@shaadescs

I using below codes to achieve , but not working...........

import { StyleSheet, Text, View } from 'react-native'
import React from 'react'
import { BarChart, YAxis } from 'react-native-charts-wrapper';

export default function BarCharsScreen({navigation}) {

const data = {
dataSets: [
  {
    values: [5000, 100000, 5000000, 10000000],
    label: 'Amounts',
  },
],

};

const formatLargeNumbers = (value) => {
if (value >= 10000000) {
  return `${(value / 10000000).toFixed(1)} Cr`;
} else if (value >= 100000) {
  return `${(value / 100000).toFixed(1)} L`; 
} else if (value >= 1000) {
  return `${(value / 1000).toFixed(1)} K`; 
}
return value.toString(); 

};

return (
<View style={{width:"100%", height:"100%"}}>
<BarChart
style={styles.chart}
data={data}
chartDescription={{ text: '' }}
xAxis={{
granularityEnabled: true,
granularity: 1,
}}
yAxis={{
left: {
valueFormatter: (value) => formatLargeNumbers(value),
granularityEnabled: true,
},
right: {
enabled: false,
},
}}
/>

)
}

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
padding: 10,
},
yAxis: {
flex: 0.2,
marginRight: 10,
},
chart: {
flex: 1,
},
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions