|
|
@@ -1,6 +1,6 @@
|
|
|
/**
|
|
|
* Created by hujs on 2020/11/12
|
|
|
- * Desc: 折线图Demo
|
|
|
+ * Desc: 折线图
|
|
|
*/
|
|
|
|
|
|
import React, { Component } from 'react'
|
|
|
@@ -23,44 +23,25 @@ export default class LineChart extends Component {
|
|
|
}
|
|
|
|
|
|
render () {
|
|
|
-
|
|
|
- const data = [
|
|
|
- { month: 'Jan', city: 'Tokyo', temperature: 7 },
|
|
|
- { month: 'Jan', city: 'London', temperature: 3.9 },
|
|
|
- { month: 'Feb', city: 'Tokyo', temperature: 6.9 },
|
|
|
- { month: 'Feb', city: 'London', temperature: 4.2 },
|
|
|
- { month: 'Mar', city: 'Tokyo', temperature: 9.5 },
|
|
|
- { month: 'Mar', city: 'London', temperature: 5.7 },
|
|
|
- { month: 'Apr', city: 'Tokyo', temperature: 14.5 },
|
|
|
- { month: 'Apr', city: 'London', temperature: 8.5 },
|
|
|
- { month: 'May', city: 'Tokyo', temperature: 18.4 },
|
|
|
- { month: 'May', city: 'London', temperature: 11.9 },
|
|
|
- { month: 'Jun', city: 'Tokyo', temperature: 21.5 },
|
|
|
- { month: 'Jun', city: 'London', temperature: 15.2 },
|
|
|
- { month: 'Jul', city: 'Tokyo', temperature: 25.2 },
|
|
|
- { month: 'Jul', city: 'London', temperature: 17 },
|
|
|
- { month: 'Aug', city: 'Tokyo', temperature: 26.5 },
|
|
|
- { month: 'Aug', city: 'London', temperature: 16.6 },
|
|
|
- { month: 'Sep', city: 'Tokyo', temperature: 23.3 },
|
|
|
- { month: 'Sep', city: 'London', temperature: 14.2 },
|
|
|
- { month: 'Oct', city: 'Tokyo', temperature: 18.3 },
|
|
|
- { month: 'Oct', city: 'London', temperature: 10.3 },
|
|
|
- { month: 'Nov', city: 'Tokyo', temperature: 13.9 },
|
|
|
- { month: 'Nov', city: 'London', temperature: 6.6 },
|
|
|
- { month: 'Dec', city: 'Tokyo', temperature: 9.6 },
|
|
|
- { month: 'Dec', city: 'London', temperature: 4.8 },
|
|
|
- ]
|
|
|
+ let { data, title } = this.props
|
|
|
+ var keyArr = []
|
|
|
+ data = data.data
|
|
|
+ for (let i in data[0]) {
|
|
|
+ keyArr.push(i)
|
|
|
+ }
|
|
|
return (
|
|
|
- <div className='charts-line'>
|
|
|
- <Chart width="100%" data={data} pixelRatio={window.devicePixelRatio * 2}>
|
|
|
- <Axis dataKey="month"/>
|
|
|
- <Axis dataKey="temperature"/>
|
|
|
+ <div className='charts-line' style={{ width: '100%', backgroundColor: '#fff' }}>
|
|
|
+ <div className="ant-table-title">{title}</div>
|
|
|
+ <Chart height={240} data={data} pixelRatio={window.devicePixelRatio * 2}>
|
|
|
+ <Axis dataKey={keyArr[0]} label={{ fontSize: 12 }}/>
|
|
|
+ <Axis dataKey={keyArr[1]} label={{ fontSize: 12 }}/>
|
|
|
{/* 点击悬浮信息 */}
|
|
|
<Tooltip showCrosshairs/>
|
|
|
{/* 顶部标题 */}
|
|
|
<Legend align="center"/>
|
|
|
- <Geom geom="line" position="month*temperature" color="city"/>
|
|
|
- <Geom geom="point" position="month*temperature" color="city" style={{ lineWidth: 1, stroke: '#FFF' }}/>
|
|
|
+ <Geom geom="line" position={keyArr[0] + '*' + keyArr[1]} color={keyArr[2]}/>
|
|
|
+ <Geom geom="point" position={keyArr[0] + '*' + keyArr[1]} color={keyArr[2]}
|
|
|
+ style={{ lineWidth: 1, stroke: '#FFF' }}/>
|
|
|
</Chart>
|
|
|
</div>
|
|
|
)
|