首页 > 解决方案 > 如何使 rechart 的 lineChart DOT 像滑块的拇指一样移动?

问题描述

目前,lineChart 的标签和点连接到 rc 滑块,并且随着滑块的拇指移动标签和点移动并相应地显示相应的数据。

我还希望线条的 DOT 像滑块的拇指一样工作(DOT 应该在线上可拖动)

图表和滑块的数据长度相同

在 CustomizedLabel 和 CustomizedDot 函数中,如果图表的数据索引 === 滑块的数据索引,我只是渲染它们

如果不可能,请有人建议另一个库或可能的方法。谢谢你。

折线图代码

<LineChart data={sliderChartData}>
            <XAxis tick={false} dataKey="name" />
            <YAxis tick={false} />
            <ReferenceLine
              y={0}
              strokeWidth={2}
              stroke={dashedLineColor}
              strokeDasharray="3 3"
            />
            <Line
              type="monotone"
              activeDot={false}
              dot={<CustomizedDot />}
              dataKey="tranchA"
              stroke={lightBlueColor}
              strokeWidth={4}
            >
              <LabelList
                dataKey="tranchA"
                content={renderCustomizedLabelTrancheA}
              />
            </Line>
            <Line
              type="monotone"
              activeDot={false}
              dot={<CustomizedDot />}
              dataKey="tranchB"
              stroke={lightBlueColor}
              strokeWidth={4}
            >
              <LabelList
                dataKey="tranchB"
                content={renderCustomizedLabelTrancheB}
              />
            </Line>
          </LineChart>

这是图表

标签: reactjsd3.jslinechartrechartsrc-slider

解决方案


推荐阅读