gpt4 book ai didi

react-native - 带有 react-native-chart-kit 的条形图中的实心条

转载 作者:行者123 更新时间:2023-12-04 16:25:59 31 4
gpt4 key购买 nike

我正在使用 https://www.npmjs.com/package/react-native-chart-kit并且正在尝试制作一个图表以匹配以下设计规范:

enter image description here

我可以获得大多数选项来使用此问题末尾附加的代码,但是我似乎无法弄清楚如何删除每个单独条的不透明度,所以它最终看起来像这样:

enter image description here

我一直在研究源代码并使用 Prop 和样式无济于事。任何帮助将不胜感激!

const { width: screenWidth } = Dimensions.get('window');

export type DataSet = {
data: Array<Number>;
};

export type BarChartData = {
labels: Array<String>;
datasets: Array<DataSet>;
};

export interface SalesChartProps {
data: BarChartData;
}

const chartConfig = {
backgroundGradientFrom: '#Ffffff',
backgroundGradientTo: '#ffffff',
barPercentage: 1.3,
decimalPlaces: 0, // optional, defaults to 2dp
color: (opacity = 1) => `rgba(1, 122, 205, 1)`,
labelColor: (opacity = 1) => `rgba(0, 0, 0, 1)`,

style: {
borderRadius: 16,
fontFamily: 'Bogle-Regular',
},
propsForBackgroundLines: {
strokeWidth: 1,
stroke: '#efefef',
strokeDasharray: '0',
},
propsForLabels: {
fontFamily: 'Bogle-Regular',
},
};

const SalesBarChart: FunctionComponent<SalesChartProps> = (
props: SalesChartProps,
) => (
<>
<Text style={styles.chartTitle}> Sales </Text>
<BarChart
style={styles.graphStyle}
showBarTops={false}
showValuesOnTopOfBars={true}
withInnerLines={true}
segments={3}
data={props.data}
width={screenWidth - 15}
height={175}
yAxisLabel=""
chartConfig={chartConfig}
verticalLabelRotation={0}
/>
</>
);

const styles = StyleSheet.create<{
graphStyle: ViewStyle;
chartTitle: TextStyle;
}>({
graphStyle: {
flex: 1,
paddingRight: 25,
},
chartTitle: {
paddingLeft: 20,
paddingBottom: 20,
paddingTop: 10,
fontFamily: 'Bogle-Regular',
fontSize: 16,
},
})

//storybook file:
const data: BarChartData = {
labels: ['9/19', '9/20', '9/21', '9/22', '9/23', '9/24', '9/25'],
datasets: [
{
data: [5, 0, 2, 4, 6, 3, 0],
},
],
};

const props = {
data,
};

storiesOf('SalesChart', module)
.addDecorator(withKnobs)
.add('BarChart', () => <SalesChart {...props} />);

最佳答案

我发现了这个可怕的解决方案,如果您在图表配置中使用高度并将其放置一个非常高的数字,则条形看起来是实心的,例如:

const chartConfig = {
backgroundGradientFrom: "#fff",
backgroundGradientTo: "#fff",
barPercentage: 0.7,
height:5000,
fillShadowGradient: `rgba(1, 122, 205, 1)`,
fillShadowGradientOpacity: 1,
decimalPlaces: 0, // optional, defaults to 2dp
color: (opacity = 1) => `rgba(1, 122, 205, 1)`,
labelColor: (opacity = 1) => `rgba(0, 0, 0, 1)`,

style: {
borderRadius: 16,
fontFamily: "Bogle-Regular",
},
propsForBackgroundLines: {
strokeWidth: 1,
stroke: "#e3e3e3",
strokeDasharray: "0",
},
propsForLabels: {
fontFamily: "Bogle-Regular",
},
};

enter image description here

关于react-native - 带有 react-native-chart-kit 的条形图中的实心条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64035350/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com