Merge pull request '折线图数据修改' (#20) from pc-master into portal

Reviewed-on: #20
pull/34/head^2
xiaomeng 2023-10-18 07:43:22 +00:00
commit 4aea05d5d2
1 changed files with 209 additions and 444 deletions

View File

@ -1,39 +1,197 @@
import * as echarts from "echarts"; import * as echarts from "echarts";
export function realTimeLine(id,data) { export function realTimeLine(id, data) {
var chartDom = document.getElementById(id); var chartDom = document.getElementById(id);
var myChart = echarts.init(chartDom); var myChart = echarts.init(chartDom);
var Xdata=[] var Xdata = []
var data1=[]//目标水肥PH var colorList1 = ['rgba(0, 187, 136, 1)', 'rgba(252, 125, 106, 1)', 'rgba(252, 223, 39, 1)', 'rgba(68, 214, 232, 1)',
var data2=[]//目标水肥EC 'rgba(69, 224, 155, 1)', 'rgba(82, 188, 255, 1)', 'rgba(214, 162, 255, 1)', 'rgba(255, 192, 111, 1)', 'rgba(255, 156, 154, 1)', 'rgba(255, 156, 154, 1)']
var data3=[]//平均值水肥PH var colorList = [new echarts.graphic.LinearGradient(
var data4=[]//平均值水肥EC 0,
var data5=[]//1#水肥PH 0,
var data6=[]//2#水肥PH 0,
var data7=[]//1#水肥EC 1,
var data8=[]//2#水肥EC [
var data9=[]//1#空气温度 {
var data10=[]//1#管道压力 offset: 0,
data.forEach((el,index)=>{ color: "rgba(0, 187, 136, 0.50)",
},
{
offset: 0.8,
color: "rgba(0, 187, 136, 0)",
},
],
false
),
new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(252, 125, 106, 0.50)",
},
{
offset: 0.8,
color: "rgba(252, 125, 106, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(252, 223, 39, 0.50)",
},
{
offset: 0.8,
color: "rgba(252, 223, 39, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(68, 214, 232, 0.50)",
},
{
offset: 0.8,
color: "rgba(68, 214, 232, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(69, 224, 155, 0.50)",
},
{
offset: 0.8,
color: "rgba(69, 224, 155, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(82, 188, 255, 0.50)",
},
{
offset: 0.8,
color: "rgba(82, 188, 255, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(214, 162, 255, 0.50)",
},
{
offset: 0.8,
color: "rgba(214, 162, 255, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 192, 111, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 192, 111, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 156, 154, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 156, 154, 0)",
},
],
false
), new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 156, 154, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 156, 154, 0)",
},
],
false
),
]
var list = []
var dataList = []
data.forEach((el, index) => {
Xdata.push(el.time) Xdata.push(el.time)
data1.push(el.value['目标水肥PH']?el.value['目标水肥PH']:0)
data2.push(el.value['目标水肥EC']?el.value['目标水肥EC']:0) el.value.forEach((el1, index1) => {
data3.push(el.value['1#平均水肥EC']?el.value['1#平均水肥EC']:0) var containsIndex = dataList.findIndex(function(item) {
data4.push(el.value['1#平均水肥PH']?el.value['1#平均水肥PH']:0) return item.name === el1.name;
data5.push(el.value['1#水肥PH']?el.value['1#水肥PH']:0) });
data6.push(el.value['2#水肥PH']?el.value['2#水肥PH']:0) if(containsIndex==-1){
data7.push(el.value['1#水肥EC']?el.value['1#水肥EC']:0) dataList.push({name:el1.name,value:[]})
data8.push(el.value['2#水肥EC']?el.value['2#水肥EC']:0) }else{
data10.push(el.value['1#管道压力']?el.value['1#管道压力']:0) dataList[containsIndex].value.push(el1.value)
data9.push(el.value['1#空气温度']?el.value['1#空气温度']:0) }
})
}) })
console.log(data1,data2); dataList.forEach((el,index)=>{
var list = [ list.push({
{ name: el.name,
name: '目标水肥PH', data: el.value,
data: data1,
type: "line", type: "line",
symbol: "circle", symbol: "circle",
smooth: true, smooth: true,
@ -46,411 +204,18 @@ export function realTimeLine(id,data) {
}, },
areaStyle: { areaStyle: {
normal: { normal: {
color: new echarts.graphic.LinearGradient( color: colorList[index],
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(0, 187, 136, 0.50)",
},
{
offset: 0.8,
color: "rgba(0, 187, 136, 0)",
},
],
false
),
}, },
}, },
itemStyle: { itemStyle: {
normal: { normal: {
color: "rgba(0, 187, 136, 1)", color: colorList1[index],
borderColor: "rgba(0, 187, 136, 1)", borderColor: colorList1[index],
borderWidth: 1, borderWidth: 1,
}, },
}, },
}, })
{ })
name: '目标水肥EC',
data:data2,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(252, 125, 106, 0.50)",
},
{
offset: 0.8,
color: "rgba(252, 125, 106, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(252, 125, 106, 1)",
borderColor: "rgba(252, 125, 106, 1)",
borderWidth: 1,
},
},
},
{
name: '平均水肥PH',
data: data3,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(252, 223, 39, 0.50)",
},
{
offset: 0.8,
color: "rgba(252, 223, 39, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(252, 223, 39, 1)",
borderColor: "rgba(252, 223, 39, 1)",
borderWidth: 1,
},
},
},
{
name: '平均水肥EC',
data: data4,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(68, 214, 232, 0.50)",
},
{
offset: 0.8,
color: "rgba(68, 214, 232, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(68, 214, 232, 1)",
borderColor: "rgba(68, 214, 232, 1)",
borderWidth: 1,
},
},
},
{
name: '1#水肥PH',
data: data5,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(69, 224, 155, 0.50)",
},
{
offset: 0.8,
color: "rgba(69, 224, 155, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(69, 224, 155, 1)",
borderColor: "rgba(69, 224, 155, 1)",
borderWidth: 1,
},
},
},
{
name: '2#水肥PH',
data: data6,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(82, 188, 255, 0.50)",
},
{
offset: 0.8,
color: "rgba(82, 188, 255, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(82, 188, 255, 1)",
borderColor: "rgba(82, 188, 255, 1)",
borderWidth: 1,
},
},
},
{
name: '1#水肥EC',
data: data7,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(214, 162, 255, 0.50)",
},
{
offset: 0.8,
color: "rgba(214, 162, 255, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(214, 162, 255, 1)",
borderColor: "rgba(214, 162, 255, 1)",
borderWidth: 1,
},
},
},
{
name: '2#水肥EC',
data:data8,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 192, 111, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 192, 111, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(255, 192, 111, 1)",
borderColor: "rgba(255, 192, 111, 1)",
borderWidth: 1,
},
},
},
{
name: '1#空气温度',
data: data9,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 156, 154, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 156, 154, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(255, 156, 154, 1)",
borderColor: "rgba(255, 156, 154, 1)",
borderWidth: 1,
},
},
},
{
name: '1#管道压力',
data: data10,
type: "line",
symbol: "circle",
smooth: true,
symbolSize: 5,
showSymbol: false,
lineStyle: {
normal: {
width: 2,
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 156, 154, 0.50)",
},
{
offset: 0.8,
color: "rgba(255, 156, 154, 0)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "rgba(255, 156, 154, 1)",
borderColor: "rgba(255, 156, 154, 1)",
borderWidth: 1,
},
},
}]
var option = { var option = {
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
@ -473,25 +238,25 @@ export function realTimeLine(id,data) {
}, },
dataZoom: [ dataZoom: [
{ {
show: true, show: true,
realtime: true, realtime: true,
start: 30, start: 30,
end: 70, end: 70,
xAxisIndex: [0, 1] xAxisIndex: [0, 1]
}, },
{ {
type: 'inside', type: 'inside',
realtime: true, realtime: true,
start: 30, start: 30,
end: 70, end: 70,
xAxisIndex: [0, 1], xAxisIndex: [0, 1],
backgroundColor:'rgba(11, 28, 42, 0.4)', backgroundColor: 'rgba(11, 28, 42, 0.4)',
fillerColor:'rgba(2, 148, 226, 1)', fillerColor: 'rgba(2, 148, 226, 1)',
textStyle:{ textStyle: {
color:'#fff' color: '#fff'
} }
} }
], ],
grid: { grid: {
left: "3%", left: "3%",
right: "4%", right: "4%",