我正在使用React的Victory图表,而且我对发生的事情非常困惑。我收到以下错误:
Invalid prop `data` of type `object` supplied to `VictoryLabel`, expected `array`
我有这样的非常简单:
public render() {
return (
<vic.VictoryChart>
<vic.VictoryBar
data={[
{ x: 0, y: 100 },
{ x: 1, y: 150 },
{ x: 2, y: 200 },
{ x: 3, y: 50 },
{ x: 4, y: 500 },
]}
labelComponent={
<vic.VictoryLabel text={d => d.y} />
}
/>
</vic.VictoryChart>
);
}
有人可以在这里告诉我这个问题吗?我不知道为什么我收到错误!
胜利文件说:
labelComponent prop采用一个组件实例,该实例将用于呈现组件的标签
您仍然需要使用labels
的VictoryBar
prop单独定义标签。 labelComponent
的目的是进一步定制定位或添加工具提示标签等内容。
来自文档的一个例子:
<VictoryBar
data={sampleData}
labels={(d) => d.y}
style={{ labels: { fill: "white" } }}
labelComponent={<VictoryLabel dy={30}/>}
/>
这里labelComponent
prop用于移动每个标签的y轴,但我们仍然需要用单独的prop来定义标签值。希望这可以帮助!