-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6c9b42
commit 126306b
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import * as echarts from 'echarts'; | ||
|
||
// 图表预留空位,保证数据完整渲染 | ||
function yAxisMin(value) { | ||
return value.min * 0.92; | ||
} | ||
function yAxisMax(value) { | ||
return value.max * 1.08; | ||
} | ||
|
||
const Trend = (trendData) => { | ||
const chartRef = useRef(null); | ||
let lineColor = | ||
trendData[trendData.length - 1] > trendData[0] ? '#FA4444' : '#05B169'; | ||
useEffect(() => { | ||
const chartDom = chartRef.current; | ||
const myChart = echarts.init(chartDom, null, { width: 240, height: 60 }); | ||
|
||
const option = { | ||
xAxis: { | ||
type: 'category', | ||
data: [], | ||
show: false, | ||
}, | ||
yAxis: { | ||
type: 'value', | ||
show: false, | ||
min: yAxisMin, | ||
max: yAxisMax, | ||
}, | ||
series: [ | ||
{ | ||
data: trendData, | ||
type: 'line', | ||
smooth: false, | ||
lineStyle: { | ||
color: lineColor, | ||
}, | ||
symbol: 'none', | ||
}, | ||
], | ||
}; | ||
|
||
myChart.setOption(option); | ||
|
||
return () => { | ||
myChart.dispose(); // 销毁图表实例 | ||
}; | ||
}, []); | ||
|
||
return <div ref={chartRef} style={{ width: '100%', height: '60px' }} />; | ||
}; | ||
|
||
export default Trend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"project": "项目", | ||
"bot": "机器人" | ||
}, | ||
"trend": "走势", | ||
"chinese": "中国", | ||
"global": "全球", | ||
"time": "时间: ", | ||
|