我正在使用胜利聊天来显示基于时间的折线图。还使用散点图来显示点。
因为当我按下线条时我没有得到事件,所以我最终使用了散点图。
在此示例中,您可以看到值正确对齐 x 轴,图表线在星期六 30 停止。但实际结束时间应该是 Sunday-31
有什么方法可以使数据与此实现保持一致,或者请提出另一种方法。
const points = [24, 24, 23, 23, 22, 20, 21, 21, 21, 20, 22, 19, 19, 20];
const dateList = [
'2021-10-18',
'2021-10-19',
'2021-10-20',
'2021-10-21',
'2021-10-22',
'2021-10-23',
'2021-10-24',
'2021-10-25',
'2021-10-26',
'2021-10-27',
'2021-10-28',
'2021-10-29',
'2021-10-30',
'2021-10-31',
];
const DataDots = (props) => {
const { x, y, datum } = props;
const dotStat = getGraphPointStats(datum?._y);
const onPressDots = () => {
const { _x, _y } = props?.datum;
setDeviationInfo({ index: _x, value: _y });
};
return (
<TextSVG x={x} y={y} fontSize={30} onPressIn={onPressDots}>
<Circle cx={x} cy={y} fill={dotStat?.color} r={6} />
</TextSVG>
);
};
return (
<VictoryChart>
<VictoryLine name="line" interpolation="natural" data={points} />
<VictoryScatter name="points" data={points} size={2} dataComponent={<DataDots />} />
<VictoryAxis
scale="time"
tickValues={dateList}
tickFormat={(date) => {
return `${moment(date).format('ddd')}\n ${moment(date).format('DD')}`;
}}
/>
</VictoryChart>
);