Reputation: 202
I want to edit the style of my chart as follows:
But I have come to this point:
Where the only thing I would be missing is to make the line a little sharper and not look like it has opacity and remove the fill from the graph so that only the line remains.
This is my code:
import React from 'react';
import { ScrollView, Dimensions, View, Text } from 'react-native';
import {
LineChart,
BarChart,
PieChart,
ProgressChart,
ContributionGraph,
StackedBarChart
} from "react-native-chart-kit";
import Styles from './Styles';
export default function Charts(){
const chartConfig = {
backgroundGradientFromOpacity: 0,
backgroundGradientToOpacity: 0,
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
strokeWidth: 3,
barPercentage: 0.5,
useShadowColorFromDataset: false,
propsForBackgroundLines: {
strokeDasharray: "",
strokeOpacity: 0.0
},
};
return (
<View>
<ScrollView>
<View style={[Styles.chart.card]}>
<LineChart data={{
labels: ["January", "February", "March", "April", "May", "June"],
datasets: [
{
data: [
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100
]
}
]
}}
width={Dimensions.get("window").width}
height={300}
yAxisLabel={undefined}
yAxisInterval={undefined}
chartConfig={chartConfig}
withHorizontalLabels={false}
bezier
hidePointsAtIndex={[0, 1, 2, 3, 4, 5]}
style={{
}}/>
</View>
</ScrollView>
</View>
);
}
I'm using React Native with Expo and the React-Native-Chart-Kit library.
Also if there is any other library that allows a greater customization of charts much better.
Thanks for your help.
Upvotes: 0
Views: 343
Reputation: 202
I found the solution, I adjusted the chartConfig like this:
const chartConfig = {
backgroundGradientFromOpacity: 0,
backgroundGradientToOpacity: 0,
color: () => `rgba(255, 255, 255, 1)`, /* Avoid opacity */
strokeWidth: 3,
barPercentage: 0.5,
useShadowColorFromDataset: false,
propsForBackgroundLines: {
strokeDasharray: "",
strokeOpacity: 0.0
},
/* Adjusts the fill of the chart */
fillShadowGradient: 'transparent',
fillShadowGradientOpacity: 0,
fillShadowGradientFromOffset: 0,
fillShadowGradientTo: 'transparent',
fillShadowGradientToOpacity: 0,
};
Result:
Upvotes: 0