gpt4 book ai didi

javascript - 如何保持所有 activeDots 始终为 "active"而不是悬停在数据点上(重新图表)

转载 作者:行者123 更新时间:2023-11-29 15:58:31 24 4
gpt4 key购买 nike

我安装了来自 npm 的包“recharts”(最新版本 1.5.0),并正确加载了我的 React 项目的数据。

数据线和图表始终处于事件状态。我需要所有“activeDots”始终处于事件状态,而不是仅在将鼠标悬停在数据点上时才处于事件状态。

   <LineChart
width={240}
height={180}
data={data}
margin={{top: 15, right: 10, left: 10}}
>
<CartesianGrid horizontal={false} />
<XAxis
dataKey="x"
stroke="rgba(0,0,0,0.4)"
strokeWidth=".4"
scale="time"
type="number"
domain={['auto', 'auto']}
tick={{fontSize: 12}}
tickFormatter = {(unixTime) => moment(unixTime).format('MMM D')}
/>
<YAxis hide={true} />
<Tooltip content={<CustomTooltip/>}/>
<Line
connectNulls={false}
type="linear"
dataKey="pv"
stroke="#3F99F7"
strokeWidth="3"
activeDot={{ fill: '#3F99F7', stroke:'#fff', strokeWidth: 3, r: 11, className: "boxShadow" }}
dot={{ fill: '#3F99F7', stroke:'#fff', strokeWidth: 2, r: 7, className: "boxShadow" }}
/>
</LineChart>

不悬停在数据点上: not hovering

悬停在数据点上: hovering

最佳答案

这看起来像您想要的(紫色线):

const {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;
const data = [
{name: 'Page A', uv: 4000, pv: 2400, amt: 2400},
{name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
{name: 'Page C', uv: 2000, pv: 9800, amt: 2290},
{name: 'Page D', uv: 2780, pv: 3908, amt: 2000},
{name: 'Page E', uv: 1890, pv: 4800, amt: 2181},
{name: 'Page F', uv: 2390, pv: 3800, amt: 2500},
{name: 'Page G', uv: 3490, pv: 4300, amt: 2100},
];
const SimpleLineChart = React.createClass({
render () {
return (
<LineChart width={600} height={300} data={data}
margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<XAxis dataKey="name"/>
<YAxis/>
<CartesianGrid strokeDasharray="3 3"/>
<Tooltip/>
<Legend />
<Line
type="monotone"
dataKey="pv"
stroke="#8884d8"
activeDot={{ fill: '#3F99F7', stroke:'#fff', strokeWidth: 3, r: 11, className: "boxShadow" }}
dot={{ fill: '#3F99F7', stroke:'#fff', strokeWidth: 2, r: 7, className: "boxShadow" }}
/>
<Line type="monotone" dataKey="uv" stroke="#82ca9d" />
</LineChart>
);
}
})

ReactDOM.render(
<SimpleLineChart />,
document.getElementById('container')
);
body {
margin: 0;
}

#container {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
width: 800px;
height: 800px;
background-color: #fff;
}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script type="text/javascript" src="https://npmcdn.com/react@15.6.2/dist/react-with-addons.min.js"></script>
<script type="text/javascript" src="https://npmcdn.com/react-dom@15.6.2/dist/react-dom.min.js"></script>
<script type="text/javascript" src="https://npmcdn.com/prop-types/prop-types.min.js"></script>
<script type="text/javascript" src="https://npmcdn.com/recharts/umd/Recharts.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>

您的示例中的代码或多或少是相同的,这使我相信您的代码中可能还有您未找到的更多内容。

关于javascript - 如何保持所有 activeDots 始终为 "active"而不是悬停在数据点上(重新图表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55798556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com