我的折线图代码有问题。所以,我只想点击某条线来改变它的颜色,但是图表中的所有线都会改变它们的笔触颜色。这是我的代码:
export default class LineChartPresentational extends React.Component {
constructor(props) {
super();
this.state = {
isclicked: true, }}
changeStrokeclick() {
this.setState({isclicked: !this.state.isclicked} )}
render() {
let strokecolor = this.state.isclicked ? "#9da0a5" : "#2d75ed"
return (
<div>
<div id="lclastdataref" style={{ textAlign: 'right' }}>
<span>Last Data Refresh: {linechartdf.date} </span>
</div>
<div className='line-charts'>
<div className="line-chart-wrapper " style={{ width: window.innerWidth / 2, height: window.innerHeight / 2, }}>
<ResponsiveContainer>
<LineChart
width={width} height={height} margin={{ top: 20, right: 20, bottom: 20, left: 20 }} data={linechartdata} id="Line-Chart">
<XAxis dataKey={xAxisColumn} />
<YAxis domain={['auto', 'auto']} />
<Tooltip cursor={false} />
{
linechartdata.map((entry, index) => (
<Line stroke={strokecolor} onClick={this.changeStrokeclick.bind(this)} name={linechartdata[index].dataKey} strokeWidth={lineThickness} dataKey={`value${index + 1}`} dot={false} className={`value${index + 1}`}/>
))
}
</LineChart>
</ResponsiveContainer>
</div>
</div>
</div>
); }
请我真的需要你的帮助,因为你可以看到我的线条是使用循环创建的。谢谢!