图表组件接入 显示成功

This commit is contained in:
mmc
2026-05-14 15:15:50 +08:00
parent abe5631642
commit adf4c37b95
9 changed files with 673 additions and 487 deletions

View File

@@ -18,6 +18,7 @@ import { Line, Bar, Pie, } from '@ant-design/charts';
import { getWeatherData, getWeatherType } from '../lib/utils';
import WeatherDisplay from '../components/Weather';
import bgMain from '../assets/images/bgmain.jpg';
import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../components/recharts';
@@ -90,180 +91,47 @@ export default function StationDashboard() {
];
// 图表配置 —— 终极美化版(渐变+紧凑+高级)
const powerTrendConfig = {
data: [
{ time: "00:00", type: "实际", value: 1800 },
{ time: "00:00", type: "预测", value: 1600 },
{ time: "04:00", type: "实际", value: 1500 },
{ time: "04:00", type: "预测", value: 1400 },
{ time: "06:00", type: "实际", value: 8000 },
{ time: "06:00", type: "预测", value: 7500 },
{ time: "08:00", type: "实际", value: 32000 },
{ time: "08:00", type: "预测", value: 30000 },
{ time: "10:00", type: "实际", value: 58000 },
{ time: "10:00", type: "预测", value: 56000 },
{ time: "12:00", type: "实际", value: 62000 },
{ time: "12:00", type: "预测", value: 60000 },
{ time: "14:00", type: "实际", value: 59000 },
{ time: "14:00", type: "预测", value: 57000 },
{ time: "16:00", type: "实际", value: 42000 },
{ time: "16:00", type: "预测", value: 40000 },
{ time: "18:00", type: "实际", value: 12000 },
{ time: "18:00", type: "预测", value: 10000 },
{ time: "20:00", type: "实际", value: 3000 },
{ time: "20:00", type: "预测", value: 2500 },
{ time: "24:00", type: "实际", value: 1800 },
{ time: "24:00", type: "预测", value: 1600 }
],
const powerTrendData = [
{ time: '00:00', actual: 1800, predict: 1600 },
{ time: '04:00', actual: 1500, predict: 1400 },
{ time: '06:00', actual: 8000, predict: 7500 },
{ time: '08:00', actual: 32000, predict: 30000 },
{ time: '10:00', actual: 58000, predict: 56000 },
{ time: '12:00', actual: 62000, predict: 60000 },
{ time: '14:00', actual: 59000, predict: 57000 },
{ time: '16:00', actual: 42000, predict: 40000 },
{ time: '18:00', actual: 12000, predict: 10000 },
{ time: '20:00', actual: 3000, predict: 2500 },
{ time: '24:00', actual: 1800, predict: 1600 },
];
xField: 'time',
yField: 'value',
seriesField: 'type',
smooth: true,
color: ['#165DFF', '#00B42A'], // ✅ 两条线颜色
lineStyle: { lineWidth: 2 },
point: { size: 5, shape: 'circle' },
area: false,
legend: { position: 'top-left' },
yAxis: { min: 0, max: 68000 },
};
const irradianceData = [
{ time: '00:00', irradiance: 40, temperature: 14 },
{ time: '04:00', irradiance: 30, temperature: 12 },
{ time: '06:00', irradiance: 180, temperature: 16 },
{ time: '08:00', irradiance: 460, temperature: 21 },
{ time: '10:00', irradiance: 780, temperature: 27 },
{ time: '12:00', irradiance: 860, temperature: 31 },
{ time: '14:00', irradiance: 820, temperature: 30 },
{ time: '16:00', irradiance: 620, temperature: 26 },
{ time: '18:00', irradiance: 220, temperature: 20 },
{ time: '20:00', irradiance: 60, temperature: 16 },
{ time: '24:00', irradiance: 40, temperature: 14 },
];
const invEfficiencyData = [
{ device: 'INV-01', efficiency: 98.6 },
{ device: 'INV-02', efficiency: 97.8 },
{ device: 'INV-03', efficiency: 97.2 },
{ device: 'INV-04', efficiency: 96.5 },
{ device: 'INV-05', efficiency: 95.8 },
];
const irradianceConfig = {
// 👇 我已经帮你把数据改成支持多色的格式
data: [
{ time: "00:00", name: "辐照度", value: 40 },
{ time: "00:00", name: "温度", value: 14 },
{ time: "04:00", name: "辐照度", value: 30 },
{ time: "04:00", name: "温度", value: 12 },
{ time: "06:00", name: "辐照度", value: 180 },
{ time: "06:00", name: "温度", value: 16 },
{ time: "08:00", name: "辐照度", value: 460 },
{ time: "08:00", name: "温度", value: 21 },
{ time: "10:00", name: "辐照度", value: 780 },
{ time: "10:00", name: "温度", value: 27 },
{ time: "12:00", name: "辐照度", value: 860 },
{ time: "12:00", name: "温度", value: 31 },
{ time: "14:00", name: "辐照度", value: 820 },
{ time: "14:00", name: "温度", value: 30 },
{ time: "16:00", name: "辐照度", value: 620 },
{ time: "16:00", name: "温度", value: 26 },
{ time: "18:00", name: "辐照度", value: 220 },
{ time: "18:00", name: "温度", value: 20 },
{ time: "20:00", name: "辐照度", value: 60 },
{ time: "20:00", name: "温度", value: 16 },
{ time: "24:00", name: "辐照度", value: 40 },
{ time: "24:00", name: "温度", value: 14 },
],
xField: "time",
yField: "value", // 现在只用一个 value
seriesField: "name", // 按 name 区分两条线
smooth: true,
color: ["#165DFF", "#00B42A"],
point: {
size: 5,
shape: "circle",
},
area: false,
animation: {
appear: {
animation: "path-in",
duration: 1500,
},
},
grid: {
line: {
style: {
stroke: "#eee",
lineWidth: 0.5,
},
},
},
legend: {
position: "top-left",
},
yAxis: {
min: 0,
max: 900,
tickCount: 6,
},
};
const invEfficiencyConfig = {
data: [
{ device: 'INV-01', efficiency: 98.6 },
{ device: 'INV-02', efficiency: 97.8 },
{ device: 'INV-03', efficiency: 97.2 },
{ device: 'INV-04', efficiency: 96.5 },
{ device: 'INV-05', efficiency: 95.8 }
],
// 恢复为竖向柱状图:X轴是设备,Y轴是效率
xField: 'device',
yField: 'efficiency',
// 每个柱子不同颜色,效率越高越亮
color: ({ efficiency }) => {
if (efficiency >= 98) return '#00B42A'; // 亮绿(最高效)
if (efficiency >= 97) return '#52C41A'; // 草绿
if (efficiency >= 96) return '#1890FF'; // 天蓝
if (efficiency >= 95) return '#4080FF'; // 蓝色
return '#808695'; // 灰色(最低效)
},
barStyle: {
radius: [4, 4, 0, 0] // 顶部圆角,和第二张图效果一致
},
// 标签放在柱子顶部,显示百分比
label: {
position: 'top',
style: {
fontSize: 11,
fill: '#333',
fontWeight: 600
},
formatter: (item) => `${item}%`
},
// Y轴从60开始(和第二张图的刻度一致),让柱子更饱满
yAxis: {
min: 60,
max: 100,
tickCount: 5, // 控制刻度数量,显示60/70/80/90/100
label: {
formatter: (v) => `${v}`
}
},
// 隐藏X轴上的线,保持简洁
xAxis: {
line: null
},
grid: {
line: { style: { stroke: '#eee', lineWidth: 0.5 } }
},
animation: { appear: { animation: 'scale-in-y', duration: 1000 } }
};
const taskProgressConfig = {
data: [
{ type: '已完成', value: 40 },
{ type: '进行中', value: 35 },
{ type: '待开始', value: 20 },
{ type: '异常', value: 5 }
],
angleField: 'value',
colorField: 'type',
color: ['#1890ff', '#52c41a', '#faad14', '#ff4d4f'],
radius: 0.8,
innerRadius: 0.6,
legend: { position: 'right' }
};
const taskProgressData = [
{ name: '已完成', value: 40, color: '#1890ff' },
{ name: '进行中', value: 35, color: '#52c41a' },
{ name: '待开始', value: 20, color: '#faad14' },
{ name: '异常', value: 5, color: '#ff4d4f' },
];
const cardStyle = { borderRadius: 12, border: '1px solid #f0f0f0', boxShadow: '0 2px 8px rgba(0,0,0,0.04)' };
@@ -325,18 +193,77 @@ export default function StationDashboard() {
<Space direction="vertical" size={16} style={{ width: '100%' }}>
<Card title={<span style={{ fontWeight: 800 }}>发电趋势</span>} extra={<Space><SyncOutlined /><FullscreenOutlined /></Space>} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}>
<div style={{ fontSize: 12, color: '#666', marginBottom: 12 }}>今日发电功率趋势 (kW)</div>
<Line {...powerTrendConfig} height={180} />
</Card>
<UniversalLineChart
data={powerTrendData}
xKey="time"
height={220}
smooth
dot
backgroundColor="transparent"
series={[
{
key: 'actual',
name: '实际',
color: '#165DFF',
strokeWidth: 3,
},
{
key: 'predict',
name: '预测',
color: '#00B42A',
strokeWidth: 2,
},
]}
/> </Card>
<Card title={<span style={{ fontWeight: 800 }}>辐照度与温度趋势</span>} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}>
<Line {...irradianceConfig} height={180} />
</Card>
<UniversalLineChart
data={irradianceData}
xKey="time"
height={220}
smooth
dot
backgroundColor="transparent"
series={[
{
key: 'irradiance',
name: '辐照度',
color: '#165DFF',
strokeWidth: 3,
},
{
key: 'temperature',
name: '温度',
color: '#00B42A',
strokeWidth: 2,
},
]}
/> </Card>
<Card title={<span style={{ fontWeight: 800 }}>逆变器效率对比</span>} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}>
<Bar {...invEfficiencyConfig} height={180} />
</Card>
<UniversalBarChart
data={invEfficiencyData}
xKey="device"
height={220}
backgroundColor="transparent"
barSize={28}
radius={[6, 6, 0, 0]}
series={[
{
key: 'efficiency',
name: '效率',
color: '#165DFF',
},
]}
/> </Card>
<Card title={<span style={{ fontWeight: 800 }}>运维任务进度</span>} extra={<Button type="link" size="small">更多 &gt;</Button>} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<Pie {...taskProgressConfig} height={160} width={160} />
<div style={{ flex: 1, paddingLeft: 12 }}>
<UniversalPieChart
data={taskProgressData}
width={220}
height={220}
innerRadius={45}
outerRadius={70}
backgroundColor="transparent"
/> <div style={{ flex: 1, paddingLeft: 12 }}>
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: 12, color: '#999' }}>总任务</div>
<div style={{ fontSize: 20, fontWeight: 800 }}>12</div>