I am trying to align this react-native-chart-kit bar graph to the center. Bar Chart
This is code that I have currently:
<BarChart
data={{
labels: ["SU", "MO", "TU", "WE", "TH", "FR", "SA"],
datasets: [
{
data: [
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
],
},
],
}}
width={Dimensions.get("window").width - 100}
height={220}
withHorizontalLabels={false}
fromZero={true}
withInnerLines={false}
chartConfig={{
backgroundGradientFrom: dark.backgroundColor,
backgroundGradientTo: dark.backgroundColor,
decimalPlaces: 0,
fillShadowGradientFrom: accent,
fillShadowGradientTo: accent,
fillShadowGradientFromOpacity: 1,
fillShadowGradientToOpacity: 0.25,
barPercentage: 0.75,
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
}}
style={{
marginVertical: 10,
borderRadius: 10,
}}
/>
I was thinking that disabling the withHorizontalLabels attribute would also remove the space that it would take up, but it did not.
I have tried adjusting the propsForHorizontalLabels styles but with no result.
Here is a working example:
Without the Y axis.
It's a work around, since I could not remove the Yaxis and move the charts in the middle. So I wrapped the Chart in a View and I moved it to the left, so that only the Charts will be visible and not the Y axis.
Check it here: https://snack.expo.dev/@footios/charts-in-the-center