add GasChart adn GridLIst

This commit is contained in:
lb 2023-07-02 21:56:09 +08:00
parent d18ba333a5
commit 5d56366825
6 changed files with 166 additions and 110 deletions

View File

@ -0,0 +1,104 @@
import cls from './index.module.css';
import ReactECharts from 'echarts-for-react';
import * as echarts from 'echarts';
import { randomInt } from '../../../../utils';
function GasChart(props) {
const options = {
color: ['#12FFF5', '#2760FF', '#FFD160'],
grid: { top: 38, right: 12, bottom: 20, left: 48 },
xAxis: {
type: 'category',
data: Array(7)
.fill(1)
.map((_, index) => {
const today = new Date();
const dtimestamp = today - index * 24 * 60 * 60 * 1000;
return `${new Date(dtimestamp).getMonth() + 1}.${new Date(
dtimestamp,
).getDate()}`;
})
.reverse(),
axisLabel: {
color: '#fff',
fontSize: 12,
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: '#213259',
},
},
},
yAxis: {
name: '单位m³/h',
nameTextStyle: {
color: '#fff',
fontSize: 10,
align: 'right',
},
type: 'value',
axisLabel: {
color: '#fff',
fontSize: 12,
formatter: '{value}',
},
axisLine: {
show: true,
lineStyle: {
color: '#213259',
},
},
splitLine: {
lineStyle: {
color: '#213259a0',
},
},
// interval: 10,
// min: 0,
// max: 100,
},
series: [
{
data: Array(7)
.fill(1)
.map((_) => {
return randomInt(1000, 2000);
}),
type: 'line',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#12FFF540' },
{ offset: 0.5, color: '#12FFF520' },
{ offset: 1, color: '#12FFF510' },
]),
},
// smooth: true,
},
{
data: Array(7)
.fill(1)
.map((_) => {
return randomInt(1000, 2000);
}),
type: 'line',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2760FF40' },
{ offset: 0.5, color: '#2760FF20' },
{ offset: 1, color: '#2760FF10' },
]),
},
// smooth: true,
},
],
tooltip: {
trigger: 'axis',
},
};
// <ReactECharts option={options} style={{ height: '100%' }} />
return <div className="gasChart">Chart Of: {props.dataSource}</div>;
}
export default GasChart;

View File

@ -0,0 +1,7 @@
import cls from './index.module.css';
function GridList(props) {
return <div className="gridList">Grid List Of: {props.dataSource}</div>;
}
export default GridList;

View File

@ -1,123 +1,63 @@
import cls from './index.module.css';
import BottomBarItem from '../BottomBarItem';
import ReactECharts from 'echarts-for-react';
import * as echarts from 'echarts';
import { randomInt } from '../../../utils';
import { Switch, Radio } from 'antd';
import { useState } from 'react';
import GridList from './gridList';
import GasChart from './gasChart';
function GasII(props) {
const options = {
color: ['#12FFF5', '#2760FF', '#FFD160'],
grid: { top: 38, right: 12, bottom: 20, left: 48 },
xAxis: {
type: 'category',
data: Array(7)
.fill(1)
.map((_, index) => {
const today = new Date();
const dtimestamp = today - index * 24 * 60 * 60 * 1000;
return `${new Date(dtimestamp).getMonth() + 1}.${new Date(
dtimestamp,
).getDate()}`;
})
.reverse(),
axisLabel: {
color: '#fff',
fontSize: 12,
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: '#213259',
},
},
},
yAxis: {
name: '单位m³/h',
nameTextStyle: {
color: '#fff',
fontSize: 10,
align: 'right',
},
type: 'value',
axisLabel: {
color: '#fff',
fontSize: 12,
formatter: '{value}',
},
axisLine: {
show: true,
lineStyle: {
color: '#213259',
},
},
splitLine: {
lineStyle: {
color: '#213259a0',
},
},
// interval: 10,
// min: 0,
// max: 100,
},
series: [
{
data: Array(7)
.fill(1)
.map((_) => {
return randomInt(1000, 2000);
}),
type: 'line',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#12FFF540' },
{ offset: 0.5, color: '#12FFF520' },
{ offset: 1, color: '#12FFF510' },
]),
},
// smooth: true,
},
{
data: Array(7)
.fill(1)
.map((_) => {
return randomInt(1000, 2000);
}),
type: 'line',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2760FF40' },
{ offset: 0.5, color: '#2760FF20' },
{ offset: 1, color: '#2760FF10' },
]),
},
// smooth: true,
},
],
tooltip: {
trigger: 'axis',
},
};
const [dataSource, setDataSource] = useState('gas-i'); // gas-i , gas-ii
const [showChart, setShowChart] = useState(true);
function handleSwitchChange(val) {
if (val) {
//
setShowChart(true);
} else {
//
setShowChart(false);
}
}
function handleSourceChange(e) {
console.log('val', e.target.value);
if (e.target.value == 'ii') {
// II
setDataSource('gas-ii');
} else if (e.target.value == 'i') {
// I
setDataSource('gas-i');
}
}
return (
<BottomBarItem icon="pause" title="天然气流量" className={cls.gas}>
{/* 当前流量 */}
<div className={cls.currentFlow}>当前流量: 280</div>
{/* legend */}
<div className={cls.headWidget}>
<div className={cls.legend}>
<span className={cls.gasIcon}></span>
<span>天然气I</span>
</div>
<div className={cls.legend}>
<span className={cls.gas2Icon}></span>
<span>天然气II</span>
<div className="flex items-center">
<Switch size="small" defaultChecked onChange={handleSwitchChange} />
<span className={cls.switchLabel}>历史详情</span>
</div>
<Radio.Group
defaultValue="i"
buttonStyle="solid"
className={cls.radioGroup}
onChange={handleSourceChange}
>
<Radio.Button value="i" className="radio-group__item">
天然气 I
</Radio.Button>
<Radio.Button value="ii" className="radio-group__item">
天然气 II
</Radio.Button>
</Radio.Group>
</div>
<div className={cls.chart}>
<ReactECharts option={options} style={{ height: '100%' }} />
{showChart && <GasChart dataSource={dataSource} />}
{!showChart && <GridList dataSource={dataSource} />}
</div>
</BottomBarItem>
);

View File

@ -28,10 +28,15 @@
top: 20px;
right: 24px;
height: 32px;
width: 190px;
width: 410px;
display: flex;
align-items: center;
justify-content: flex-end;
justify-content: space-between;
}
.switchLabel {
color: white;
margin-left: 6px;
}
.legend:last-child {