4 changed files with 114 additions and 93 deletions
@ -0,0 +1,77 @@ |
|||
import React, { PureComponent } from 'react'; |
|||
|
|||
import { NumberInfo, MiniArea } from '../Charts'; |
|||
import { fixedZero } from '../../utils/utils'; |
|||
|
|||
import styles from './index.less'; |
|||
|
|||
function getActiveData() { |
|||
const activeData = []; |
|||
for (let i = 0; i < 24; i += 1) { |
|||
activeData.push({ |
|||
x: `${fixedZero(i)}:00`, |
|||
y: (i * 50) + (Math.floor(Math.random() * 200)), |
|||
}); |
|||
} |
|||
return activeData; |
|||
} |
|||
|
|||
export default class ActiveChart extends PureComponent { |
|||
state = { |
|||
activeData: getActiveData(), |
|||
} |
|||
|
|||
componentDidMount() { |
|||
setInterval(() => { |
|||
this.setState({ |
|||
activeData: getActiveData(), |
|||
}); |
|||
}, 1000); |
|||
} |
|||
|
|||
render() { |
|||
const { activeData = [] } = this.state; |
|||
|
|||
return ( |
|||
<div className={styles.activeChart}> |
|||
<NumberInfo |
|||
subTitle="目标评估" |
|||
total="有望达到预期" |
|||
/> |
|||
<div style={{ marginTop: 32 }}> |
|||
<MiniArea |
|||
animate={false} |
|||
line |
|||
color="#5DD1DD" |
|||
height={84} |
|||
yAxis={{ |
|||
tickCount: 3, |
|||
tickLine: false, |
|||
labels: false, |
|||
title: false, |
|||
line: false, |
|||
}} |
|||
data={activeData} |
|||
/> |
|||
</div> |
|||
{ |
|||
activeData && ( |
|||
<div className={styles.activeChartGrid}> |
|||
<p>{[...activeData].sort()[activeData.length - 1].y + 200} 亿元</p> |
|||
<p>{[...activeData].sort()[Math.floor(activeData.length / 2)].y} 亿元</p> |
|||
</div> |
|||
) |
|||
} |
|||
{ |
|||
activeData && ( |
|||
<div className={styles.activeChartLegend}> |
|||
<span>00:00</span> |
|||
<span>{activeData[Math.floor(activeData.length / 2)].x}</span> |
|||
<span>{activeData[activeData.length - 1].x}</span> |
|||
</div> |
|||
) |
|||
} |
|||
</div> |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
@import "~antd/lib/style/themes/default.less"; |
|||
@import "../../utils/utils.less"; |
|||
|
|||
.activeChart { |
|||
position: relative; |
|||
} |
|||
.activeChartGrid { |
|||
p { |
|||
position: absolute; |
|||
top: 80px; |
|||
} |
|||
p:last-child { |
|||
top: 115px; |
|||
} |
|||
} |
|||
.activeChartLegend { |
|||
position: relative; |
|||
font-size: 0; |
|||
margin-top: 8px; |
|||
height: 20px; |
|||
line-height: 20px; |
|||
span { |
|||
display: inline-block; |
|||
font-size: 12px; |
|||
text-align: center; |
|||
width: 33.33%; |
|||
} |
|||
span:first-child { |
|||
text-align: left; |
|||
} |
|||
span:last-child { |
|||
text-align: right; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue