我在 VictoryChart 中显示股票数据,其中x
是代表天数的数字(即简单的 0、1、2、3... 等),y
是当天的价格。
我为 VictoryChart 设置了一个域(从最低值到最高值),并且我有一个VictoryLine
正确显示的域。
我想在最低和最高价格所在的位置添加一些“浮动”标签(不在下图中),并且标签的坐标x
和y
坐标存在问题,因为它们似乎与我定义的域不匹配。
我注意到,如果我在图表中放置一个位置 x = 0,y = 0 的标签,那么它位于左上角(我希望是左下角)。这是它目前的样子,带有一些测试标签:
代码:
<VictoryChart
domain={{ x: [startPrice.x, endPrice.x], y: [Math.floor(lowestPrice.y), Math.ceil(highestPrice.y)] }}
>
<VictoryLine
style={{
data: { stroke: '#4CB872', strokeWidth: 4 },
}}
data={chartData}
animate={{
duration: 1000,
onLoad: { duration: 1000 },
}}
/>
<VictoryLine
style={{ data: { stroke: Colors.Beige, strokeDasharray: '2,5', strokeWidth: 1, opacity: 0.5 } }}
data={chartData.map((datum) => ({ x: datum.x, y: chartData[0].y }))}
animate={{
duration: 1000,
onLoad: { duration: 1000 },
}}
></VictoryLine>
<VictoryLabel text='x10 y10' x={10} y={10} />
<VictoryLabel text='x100 y100' x={100} y={100} />
<VictoryLabel text='x200 y200' x={200} y={200} />
</VictoryChart>
chartData
例如:
"chartData": [
{
"date": "2020-09-21",
"x": 0,
"y": 142.31579017,
},
{
"date": "2020-09-22",
"x": 1,
"y": 142.31420395,
},
{
"date": "2020-09-23",
"x": 2,
"y": 142.16096094,
},
{
"date": "2020-09-24",
"x": 3,
"y": 142.09860251,
},
...
关于我定义的域,我如何使用VictoryLabel
s 上的 x/y 定位将它们放置在图表上?例如,标有“x100 y100”的标签不应位于位置 x=100,y=100 而是 x=5,y=142.5 或附近。