173 lines
4.2 KiB
JavaScript
173 lines
4.2 KiB
JavaScript
import GraphBase from "../../../Common/GraphBase";
|
|
import ReactECharts from "echarts-for-react";
|
|
// import getOptions from "../../../../hooks/getChartOption";
|
|
import { useSelector } from "react-redux";
|
|
import { useState } from "react";
|
|
import * as echarts from "echarts";
|
|
import dayjs from "dayjs";
|
|
|
|
function NO(props) {
|
|
const dayTrend = useSelector((state) => state.smoke?.dayTrend);
|
|
const weekTrend = useSelector((state) => state.smoke?.weekTrend);
|
|
const monthTrend = useSelector((state) => state.smoke?.monthTrend);
|
|
const yearTrend = useSelector((state) => state.smoke?.yearTrend);
|
|
const [period, setPeriod] = useState("日");
|
|
const [timestr, setTimestr] = useState(
|
|
dayjs().subtract(7, "day").format("YYYY.MM.DD") +
|
|
" - " +
|
|
dayjs().subtract(1, "day").format("YYYY.MM.DD")
|
|
);
|
|
|
|
const currentTrend =
|
|
period === "日"
|
|
? dayTrend
|
|
: period === "周"
|
|
? weekTrend
|
|
: period === "月"
|
|
? monthTrend
|
|
: yearTrend;
|
|
|
|
const options = getOptions("NOX_float", period, currentTrend);
|
|
|
|
function handleSwitch(v) {}
|
|
|
|
function handleDateChange(value) {
|
|
setPeriod(value);
|
|
setTimestr(
|
|
{
|
|
日:
|
|
dayjs().subtract(1, "day").format("YYYY.MM.DD") +
|
|
" 7点 - " +
|
|
dayjs().format("YYYY.MM.DD") +
|
|
" 7点",
|
|
年:
|
|
dayjs().subtract(1, "year").endOf("year").format("YYYY.MM.") +
|
|
"29 - " +
|
|
dayjs().endOf("year").format("YYYY.MM.") +
|
|
"28",
|
|
周:
|
|
dayjs().subtract(7, "day").format("YYYY.MM.DD") +
|
|
" - " +
|
|
dayjs().subtract(1, "day").format("YYYY.MM.DD"),
|
|
月:
|
|
dayjs().subtract(1, "month").format("YYYY.MM.") +
|
|
"29 - " +
|
|
dayjs().format("YYYY.MM.") +
|
|
"28",
|
|
}[value]
|
|
);
|
|
}
|
|
return (
|
|
<GraphBase
|
|
icon="smoke"
|
|
title="氮氧化物"
|
|
desc={`能耗趋势图 ${timestr}`}
|
|
switchOptions={false}
|
|
defaultSelect={period}
|
|
onSwitch={handleSwitch}
|
|
dateOptions={["日", "周", "月", "年"]}
|
|
onDateChange={handleDateChange}
|
|
size={["long", "middle"]}
|
|
>
|
|
{options && (
|
|
<ReactECharts
|
|
key={Math.random()}
|
|
option={options}
|
|
style={{ height: "100%" }}
|
|
/>
|
|
)}
|
|
{!options && (
|
|
<p
|
|
style={{
|
|
color: "#cccf",
|
|
fontSize: "24px",
|
|
userSelect: "none",
|
|
textAlign: "center",
|
|
paddingTop: "96px",
|
|
}}
|
|
>
|
|
暂无数据
|
|
</p>
|
|
)}
|
|
</GraphBase>
|
|
);
|
|
}
|
|
|
|
export default NO;
|
|
|
|
function getOptions(source, period, trend) {
|
|
if (
|
|
trend[source].length == 0 ||
|
|
trend[source].filter((item) => item.value).length == 0
|
|
)
|
|
return null;
|
|
return {
|
|
color: ["#FFD160", "#12FFF5", "#2760FF"],
|
|
grid: { top: 40, right: 12, bottom: 20, left: 64 },
|
|
xAxis: {
|
|
type: "category",
|
|
data: trend[source].map((item) => item.time),
|
|
axisLabel: {
|
|
color: "#fff",
|
|
fontSize: 12,
|
|
},
|
|
axisTick: { show: false },
|
|
axisLine: {
|
|
lineStyle: {
|
|
width: 1,
|
|
color: "#213259",
|
|
},
|
|
},
|
|
},
|
|
yAxis: {
|
|
name: "单位mg/m³",
|
|
nameTextStyle: {
|
|
color: "#fff",
|
|
fontSize: 12,
|
|
align: "right",
|
|
},
|
|
type: "value",
|
|
axisLabel: {
|
|
color: "#fff",
|
|
fontSize: 12,
|
|
formatter: "{value}",
|
|
},
|
|
axisLine: {
|
|
show: true,
|
|
lineStyle: {
|
|
color: "#213259",
|
|
},
|
|
},
|
|
splitLine: {
|
|
lineStyle: {
|
|
color: "#213259a0",
|
|
},
|
|
},
|
|
},
|
|
series: [
|
|
{
|
|
data: trend[source].map((item) =>
|
|
!(item.value == null || isNaN(+item.value))
|
|
? (+item.value).toFixed(2)
|
|
: null
|
|
),
|
|
type: "line",
|
|
areaStyle: {
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
{ offset: 0, color: "#FFD16040" },
|
|
{ offset: 0.5, color: "#FFD16020" },
|
|
{ offset: 1, color: "#FFD16010" },
|
|
]),
|
|
},
|
|
},
|
|
],
|
|
tooltip: {
|
|
trigger: "axis",
|
|
axisPointer: {
|
|
type: "shadow",
|
|
},
|
|
className: "xc-chart-tooltip",
|
|
},
|
|
};
|
|
}
|