我想编辑图表的样式如下:
但我已经走到了这一步:
我唯一缺少的就是使线条更清晰一点,并且看起来不透明,并从图表中删除填充,以便仅保留线条。
这是我的代码:
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>
);
}
我将 React Native 与 Expo 和 React-Native-Chart-Kit 库一起使用。
此外,如果有任何其他库可以更好地自定义图表,那就更好了。
感谢您的帮助。
我找到了解决方案,我像这样调整了chartConfig:
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,
};
结果: