【发布时间】:2019-07-07 16:03:56
【问题描述】:
我的 VictoryBar 图表无法在我的 React Native 应用程序中正确显示标签。 x 轴代表天数,y 轴代表数值。我想显示图表 每个条形上方的值,但它显示日期。我已经设置了标签属性,但它什么也没做。如图所示,当我 console.log(d) 时没有任何反应。这段代码的结果如下。
"react-native": "0.59.9" “胜利原生”:“^32.0.2” "react-native-svg": "^9.5.1",
谢谢
<VictoryChart domainPadding={70}>
<VictoryBar
data={bars}
x="label"
y="value"
// animate={{ onLoad: { duration: 1000 } }}
style={{ data: { width: 20, fill: (d) => d.x === 3 ? "#000000" : "#49C6B7" }}}
labels={(d)=>{console.log(d);return d.y}}
/>
<VictoryAxis
//x
tickLabelComponent={<VictoryLabel angle={45} />}
style={{
axis: {stroke: 'grey'},
ticks: {stroke: 'white'},
tickLabels: {fontSize: 12, padding: 3, marginLeft:10, stroke:"white", verticalAnchor: "middle", textAnchor:'start'}
}}
/>
<VictoryAxis
//y
tickFormat={(d)=> numeral(d).format('0.0a')}
dependentAxis
style={{
axis: {stroke: "grey"},
grid: {stroke:'grey'},
tickLabels: {fontSize: 0, padding: 0, stroke:'white'}
}}
/>
</VictoryChart>
【问题讨论】:
-
好的...通过将数据更改为具有“x”和“y”值的对象数组来保存自己。而不是 x 和 y,我有“标签”和“价值”。否则,我无法弄清楚如何完成这项工作。
-
可以分享一下,如何在 Y 轴上显示 K 和 M 的值,因为我无法显示超过 1,00,000 个值。可以请帮助我。我卡住了。谢谢
标签: react-native victory-charts