ECharts 智慧能源监控平台实战
📋 项目概述
构建能源管理与监控系统,可视化展示能源消耗、发电效率、碳排放等关键能源数据。
核心功能
- ✅ 能耗监控:实时用电量/用水量
- ✅ 发电分析:太阳能/风能发电效率
- ✅ 碳排放:碳足迹追踪与预测
- ✅ 负荷预测:用电负荷趋势分析
- ✅ 成本分析:能源费用统计
💻 核心实现
1. 能源消耗桑基图
typescript
// components/Energy/EnergyFlowSankey.tsx
import React, { useMemo } from 'react';
import * as echarts from 'echarts/core';
import { SankeyChart } from 'echarts/charts';
import {
TooltipComponent,
TitleComponent
} from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import BaseChart from '@/components/Chart/BaseChart';
echarts.use([
SankeyChart,
TooltipComponent,
TitleComponent,
CanvasRenderer
]);
interface EnergyFlow {
source: string;
target: string;
value: number;
unit: string;
}
interface EnergyFlowSankeyProps {
flows: EnergyFlow[];
title?: string;
}
const EnergyFlowSankey: React.FC<EnergyFlowSankeyProps> = ({ flows, title }) => {
const option = useMemo(() => {
// 提取所有节点
const nodeSet = new Set<string>();
flows.forEach(flow => {
nodeSet.add(flow.source);
nodeSet.add(flow.target);
});
const nodes = Array.from(nodeSet).map(name => ({ name }));
return {
title: {
text: title || '能源流向分析',
left: 'center'
},
tooltip: {
trigger: 'item',
triggerOn: 'mousemove',
formatter: (params: any) => {
if (params.dataType === 'edge') {
return `
<div style="padding: 8px;">
<div>${params.data.source} → ${params.data.target}</div>
<div>用量: ${params.data.value.toLocaleString()} kWh</div>
</div>
`;
}
return `
<div style="padding: 8px;">
<div style="font-weight: bold;">${params.data.name}</div>
</div>
`;
}
},
series: {
type: 'sankey',
layout: 'none',
emphasis: {
focus: 'adjacency'
},
data: nodes,
links: flows.map(flow => ({
source: flow.source,
target: flow.target,
value: flow.value
})),
levels: [
{
depth: 0,
itemStyle: { color: '#5470c6' },
lineStyle: { color: 'source', opacity: 0.6 }
},
{
depth: 1,
itemStyle: { color: '#91cc75' },
lineStyle: { color: 'source', opacity: 0.6 }
},
{
depth: 2,
itemStyle: { color: '#fac858' },
lineStyle: { color: 'source', opacity: 0.6 }
},
{
depth: 3,
itemStyle: { color: '#ee6666' },
lineStyle: { color: 'source', opacity: 0.6 }
}
],
lineStyle: {
curveness: 0.5
},
label: {
formatter: '{b}\n{c} kWh'
}
}
};
}, [flows, title]);
return <BaseChart option={option} height={600} />;
};
export default EnergyFlowSankey;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
2. 发电效率仪表盘
typescript
// components/Energy/PowerGenerationGauge.tsx
import React, { useMemo } from 'react';
import * as echarts from 'echarts/core';
import { GaugeChart, PieChart } from 'echarts/charts';
import BaseChart from '@/components/Chart/BaseChart';
interface PowerGenData {
solar: {
current: number; // 当前发电量 (kWh)
capacity: number; // 装机容量 (kW)
efficiency: number; // 转换效率 (%)
};
wind: {
current: number;
capacity: number;
efficiency: number;
};
totalConsumption: number;
}
interface PowerGenerationGaugeProps {
data: PowerGenData;
}
const PowerGenerationGauge: React.FC<PowerGenerationGaugeProps> = ({ data }) => {
// 太阳能发电仪表盘
const solarOption = useMemo(() => ({
series: [{
type: 'gauge',
min: 0,
max: data.solar.capacity,
startAngle: 210,
endAngle: -30,
radius: '90%',
center: ['50%', '55%'],
progress: {
show: true,
width: 20,
itemStyle: { color: '#fac858' }
},
pointer: {
length: '70%',
width: 6
},
axisLine: {
lineStyle: {
width: 20,
color: [[1, '#e0e6f1']]
}
},
axisTick: { show: false },
splitLine: { show: false },
axisLabel: { show: false },
title: {
offsetCenter: [0, '-20%'],
fontSize: 16,
color: '#666'
},
detail: {
fontSize: 24,
offsetCenter: [0, '10%'],
formatter: (value: number) => {
return `{value|${value.toFixed(1)}}{unit|kWh}`;
},
rich: {
value: {
fontSize: 24,
fontWeight: 'bold',
color: '#fac858'
},
unit: {
fontSize: 14,
color: '#999',
padding: [0, 0, 0, 4]
}
}
},
data: [{
value: data.solar.current,
name: '太阳能发电'
}]
}]
}), [data.solar]);
// 能源结构饼图
const energyMixOption = useMemo(() => {
const total = data.solar.current + data.wind.current;
const solarPercent = (data.solar.current / total * 100).toFixed(1);
const windPercent = (data.wind.current / total * 100).toFixed(1);
return {
tooltip: {
trigger: 'item',
formatter: '{b}: {c} kWh ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [{
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: true,
formatter: '{b}\n{d}%'
},
data: [
{
value: data.solar.current,
name: '太阳能',
itemStyle: { color: '#fac858' }
},
{
value: data.wind.current,
name: '风能',
itemStyle: { color: '#73c0de' }
}
]
}]
};
}, [data]);
return (
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px' }}>
<BaseChart option={solarOption} height={250} />
<BaseChart option={energyMixOption} height={250} />
</div>
);
};
export default PowerGenerationGauge;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
3. 碳排放趋势图
typescript
// components/Energy/CarbonEmissionTrend.tsx
import React, { useMemo } from 'react';
import * as echarts from 'echarts/core';
import { LineChart, BarChart } from 'echarts/charts';
import {
GridComponent,
TooltipComponent,
LegendComponent,
DataZoomComponent,
MarkLineComponent
} from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import BaseChart from '@/components/Chart/BaseChart';
echarts.use([
LineChart,
BarChart,
GridComponent,
TooltipComponent,
LegendComponent,
DataZoomComponent,
MarkLineComponent,
CanvasRenderer
]);
interface CarbonData {
date: string;
emission: number; // 碳排放量 (吨CO2)
reduction: number; // 减排量 (吨CO2)
intensity: number; // 碳强度 (kgCO2/kWh)
target: number; // 减排目标
}
interface CarbonEmissionTrendProps {
data: CarbonData[];
}
const CarbonEmissionTrend: React.FC<CarbonEmissionTrendProps> = ({ data }) => {
const option = useMemo(() => ({
title: {
text: '碳排放趋势分析',
left: 'center'
},
tooltip: {
trigger: 'axis',
axisPointer: { type: 'cross' }
},
legend: {
data: ['碳排放量', '减排量', '碳强度', '减排目标'],
top: 30
},
grid: [
{
left: '3%',
right: '4%',
height: '50%',
top: '15%',
containLabel: true
},
{
left: '3%',
right: '4%',
height: '30%',
top: '60%',
containLabel: true
}
],
xAxis: [
{
type: 'category',
data: data.map(d => d.date),
axisTick: { alignWithLabel: true }
}
],
yAxis: [
{
type: 'value',
name: '碳排放量 (吨)',
position: 'left',
gridIndex: 0
},
{
type: 'value',
name: '碳强度 (kg/kWh)',
position: 'right',
gridIndex: 0
},
{
type: 'value',
name: '减排量 (吨)',
position: 'left',
gridIndex: 1
}
],
dataZoom: [{
type: 'inside',
start: 0,
end: 100
}],
series: [
{
name: '碳排放量',
type: 'bar',
data: data.map(d => d.emission),
itemStyle: { color: '#ff6b6b' },
xAxisIndex: 0,
yAxisIndex: 0
},
{
name: '减排量',
type: 'bar',
data: data.map(d => d.reduction),
itemStyle: { color: '#52c41a' },
xAxisIndex: 0,
yAxisIndex: 2
},
{
name: '碳强度',
type: 'line',
yAxisIndex: 1,
data: data.map(d => d.intensity),
smooth: true,
itemStyle: { color: '#5470c6' },
markLine: {
data: [
{
type: 'average',
name: '平均值'
}
]
}
},
{
name: '减排目标',
type: 'line',
data: data.map(d => d.target),
lineStyle: {
color: '#faad14',
type: 'dashed',
width: 2
},
symbol: 'none'
}
]
}), [data]);
return <BaseChart option={option} height={600} />;
};
export default CarbonEmissionTrend;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
4. 用电负荷预测
typescript
// components/Energy/LoadForecast.tsx
import React, { useMemo } from 'react';
import * as echarts from 'echarts/core';
import { LineChart } from 'echarts/charts';
import {
GridComponent,
TooltipComponent,
LegendComponent
} from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import BaseChart from '@/components/Chart/BaseChart';
echarts.use([
LineChart,
GridComponent,
TooltipComponent,
LegendComponent,
CanvasRenderer
]);
interface LoadForecastData {
time: string;
actual: number | null; // 实际负荷
predicted: number | null; // 预测负荷
upperBound: number | null; // 上界
lowerBound: number | null; // 下界
}
interface LoadForecastProps {
data: LoadForecastData[];
}
const LoadForecast: React.FC<LoadForecastProps> = ({ data }) => {
const option = useMemo(() => ({
title: {
text: '用电负荷预测',
subtext: '阴影区域表示预测区间',
left: 'center'
},
tooltip: {
trigger: 'axis',
formatter: (params: any) => {
let html = `<div style="padding: 8px;">`;
html += `<div style="margin-bottom: 4px;">${params[0].axisValue}</div>`;
params.forEach((param: any) => {
if (param.value !== null && param.value !== undefined) {
html += `<div style="color: ${param.color};">
${param.seriesName}: ${param.value.toFixed(2)} MW
</div>`;
}
});
html += `</div>`;
return html;
}
},
legend: {
data: ['实际负荷', '预测负荷', '预测区间'],
top: 30
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: data.map(d => d.time),
boundaryGap: false
},
yAxis: {
type: 'value',
name: '负荷 (MW)'
},
series: [
{
name: '实际负荷',
type: 'line',
data: data.map(d => d.actual),
smooth: true,
symbol: 'circle',
symbolSize: 6,
itemStyle: { color: '#5470c6' },
lineStyle: { width: 2 }
},
{
name: '预测负荷',
type: 'line',
data: data.map(d => d.predicted),
smooth: true,
symbol: 'none',
lineStyle: {
color: '#ee6666',
width: 2,
type: 'dashed'
}
},
{
name: '预测区间',
type: 'line',
data: data.map(d => d.upperBound),
smooth: true,
symbol: 'none',
lineStyle: { opacity: 0 },
areaStyle: {
color: 'rgba(238, 102, 102, 0.2)'
},
stack: 'confidence'
},
{
name: '预测区间',
type: 'line',
data: data.map(d => {
if (d.upperBound === null || d.lowerBound === null) return null;
return d.upperBound - d.lowerBound;
}),
smooth: true,
symbol: 'none',
lineStyle: { opacity: 0 },
areaStyle: {
color: 'rgba(238, 102, 102, 0.2)'
},
stack: 'confidence'
}
]
}), [data]);
return <BaseChart option={option} height={400} />;
};
export default LoadForecast;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
💎 总结
本实战案例展示了智慧能源监控的核心可视化方案:
- 能源流向:桑基图展示能源分配
- 发电监控:可再生能源效率
- 碳排放:碳足迹追踪与减排
- 负荷预测:用电需求预测
适用于智能电网、新能源管理等场景。
