2

我正在使用 react-native-chart-kit 并且我正在尝试使用任何颜色填充条形的 cbar 图表,到目前为止它是灰色的,但我正在尝试更改它,但我尝试在其中添加颜色:{}数据集部分以及 svg。但是没有成功。任何建议将不胜感激。

render() {
        return (
            <View>
                <BarChart
                    data={{
                        labels: [
                            '1',
                            '2',
                            '3',
                            '4',
                            '5',
                            '6',
                            '7'
                        ],
                        datasets: [
                            {
                                data: this.props.data,
                            },
                        ],
                    }}
                    svg={{ fill: 'green' }}
                    width={Dimensions.get('window').width - 16}
                    height={220}

                    chartConfig={{
                        backgroundColor: '#fff',
                        backgroundGradientFrom: '#fff',
                        backgroundGradientTo: '#fff',
                        decimalPlaces: 2,
                        color: (opacity = 1) => `rgba(0, 0, 0, ${opacity})`,
                        style: {
                            borderRadius: 16,
                        },
                        propsForDots: {
                            r: "0",
                            strokeWidth: "2",
                            stroke: "#fff"
                        },
                        propsForBackgroundLines: {
                            strokeWidth: 0
                        },
                    }}
                    style={{
                        marginVertical: 8,
                        borderRadius: 16,
                    }}
                />
            </View>
        );
    }
4

2 回答 2

0

您可以在 chartConfig 中设置 fillShadowGradient 和 fillShadowGradientOpacity。

更多信息:https ://github.com/indiesspirit/react-native-chart-kit#chart-style-object

于 2020-07-19T18:30:26.357 回答
0

您可以在以下行中添加

chartConfig:{{
    fillShadowGradient:'skyblue',
    fillShadowGradientOpacity:1,
}}

它的工作正常

于 2020-10-07T05:59:43.137 回答