|
|
@ -1,35 +1,57 @@ |
|
|
|
import React, { useEffect, useRef } from 'react' |
|
|
|
import React, { useEffect, useRef, useState } from 'react' |
|
|
|
import * as echarts from 'echarts'; |
|
|
|
import { getGodshuju } from "../../../../../actions/example" |
|
|
|
|
|
|
|
const Lefttopecharts = () => { |
|
|
|
|
|
|
|
const Lefttopecharts = (props) => { |
|
|
|
const { dispatch } = props |
|
|
|
const chartRef = useRef(null); |
|
|
|
const [mass, setMass] = useState() |
|
|
|
useEffect(() => { |
|
|
|
const shuju = dispatch(getGodshuju()).then((res) => { |
|
|
|
// console.log(res);
|
|
|
|
setMass(res.payload.data.index) |
|
|
|
// setspeed(res.payload.data.speed)
|
|
|
|
}) |
|
|
|
}, []) |
|
|
|
useEffect(() => { |
|
|
|
// const shuju = dispatch(getGodshuju()).then((res) => {
|
|
|
|
// // console.log(res);
|
|
|
|
// setMass(res.payload.data.index)
|
|
|
|
// // setspeed(res.payload.data.speed)
|
|
|
|
// })
|
|
|
|
console.log(mass); |
|
|
|
var chartInstance = echarts.init(chartRef.current); |
|
|
|
var dataArr = 50; |
|
|
|
// var dataArr = mass || 0;
|
|
|
|
var names = names() |
|
|
|
var colorSet = colors(); |
|
|
|
var colorSet = /* colors() *//* "red" + */ /* {mass<30?""} */"#33B000"; |
|
|
|
function names() { |
|
|
|
if (dataArr >= 0 && dataArr < 30) { |
|
|
|
return ("畅通"); |
|
|
|
} else if (dataArr >= 30 && dataArr < 50) { |
|
|
|
return ("缓行"); |
|
|
|
} else if (dataArr >= 50 && dataArr < 70) { |
|
|
|
return ("拥堵"); |
|
|
|
} else if (dataArr >= 70 && dataArr <= 100) { |
|
|
|
return ("严重拥堵"); |
|
|
|
} |
|
|
|
} |
|
|
|
function colors() { |
|
|
|
if (dataArr >= 0 && dataArr < 30) { |
|
|
|
return (colorSet = { color: "#33B000" }); |
|
|
|
} else if (dataArr >= 30 && dataArr < 50) { |
|
|
|
return (colorSet = { color: "#FECB00" }); |
|
|
|
} else if (dataArr >= 50 && dataArr < 70) { |
|
|
|
return (colorSet = { color: "#DF0001" }); |
|
|
|
} else if (dataArr >= 70 && dataArr <= 100) { |
|
|
|
return (colorSet = { color: "#8E0E0B" }); |
|
|
|
if (mass) { |
|
|
|
if (mass >= 0 && mass < 30) { |
|
|
|
return ("畅通"); |
|
|
|
} else if (mass >= 30 && mass < 50) { |
|
|
|
return ("缓行"); |
|
|
|
} else if (mass >= 50 && mass < 70) { |
|
|
|
return ("拥堵"); |
|
|
|
} else if (mass >= 70 && mass <= 100) { |
|
|
|
return ("严重拥堵"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// function colors() {
|
|
|
|
// if (mass) {
|
|
|
|
// if (mass >= 0 && mass < 30) {
|
|
|
|
// return (colorSet = { color: "#33B000" });
|
|
|
|
// } else if (mass >= 30 && mass < 50) {
|
|
|
|
// return (colorSet = { color: "#FECB00" });
|
|
|
|
// } else if (mass >= 50 && mass < 70) {
|
|
|
|
// return (colorSet = { color: "#DF0001" });
|
|
|
|
// } else if (mass >= 70 && mass <= 100) {
|
|
|
|
// return (colorSet = { color: "#8E0E0B" });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
var option = { |
|
|
|
// backgroundColor: "#0E1327",
|
|
|
|
tooltip: { |
|
|
@ -47,7 +69,7 @@ const Lefttopecharts = () => { |
|
|
|
axisLine: { |
|
|
|
lineStyle: { |
|
|
|
color: [ |
|
|
|
[dataArr / 100, colorSet.color], |
|
|
|
[mass || [] / 100, colorSet.color], |
|
|
|
[1, "#111F42"], |
|
|
|
], |
|
|
|
width: 3, |
|
|
@ -107,7 +129,7 @@ const Lefttopecharts = () => { |
|
|
|
|
|
|
|
{ |
|
|
|
name: "拥堵指数", |
|
|
|
value: dataArr, |
|
|
|
value: mass || [], |
|
|
|
itemStyle: colorSet |
|
|
|
}, |
|
|
|
], |
|
|
@ -182,7 +204,7 @@ const Lefttopecharts = () => { |
|
|
|
window.addEventListener('resize', function () { |
|
|
|
chartInstance.resize(); |
|
|
|
}) |
|
|
|
}, []); |
|
|
|
}, [mass]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
@ -196,19 +218,19 @@ const Lefttopecharts = () => { |
|
|
|
<div style={{ width: "100%", height: "20vh", marginTop: "-29%" }}> |
|
|
|
<div style={{ width: "100%", height: "5%", color: "rgba(216,240,255,0.8000)", position: "relative", top: "3%" }}> |
|
|
|
<p style={{ position: "absolute", left: "25%", top: "5%" }}><p style={{ position: "absolute", width: "10px", height: "10px", background: "#33B000", left: "-50%", top: "20%" }}></p>畅通</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>0-30</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>{"[0,30)"}</p> |
|
|
|
</div> |
|
|
|
<div style={{ width: "100%", height: "5%", color: "rgba(216,240,255,0.8000)", position: "relative", top: "11%" }}> |
|
|
|
<p style={{ position: "absolute", left: "25%", top: "5%" }}><p style={{ position: "absolute", width: "10px", height: "10px", background: "#FECB00", left: "-50%", top: "20%" }}></p>缓慢</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>30-50</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>{"[30,50)"}</p> |
|
|
|
</div> |
|
|
|
<div style={{ width: "100%", height: "5%", color: "rgba(216,240,255,0.8000)", position: "relative", top: "19%" }}> |
|
|
|
<p style={{ position: "absolute", left: "25%", top: "5%" }}><p style={{ position: "absolute", width: "10px", height: "10px", background: "#DF0001", left: "-50%", top: "20%" }}></p>拥堵</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>50-70</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>{"[50,70)"}</p> |
|
|
|
</div> |
|
|
|
<div style={{ width: "100%", height: "5%", color: "rgba(216,240,255,0.8000)", position: "relative", top: "27%" }}> |
|
|
|
<p style={{ position: "absolute", left: "25%", top: "5%" }}><p style={{ position: "absolute", width: "10px", height: "10px", background: "#8E0E0B", left: "-25%", top: "20%" }}></p>严重拥堵</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>70-100</p> |
|
|
|
<p style={{ position: "absolute", left: "60%" }}>{"[70,100]"}</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</> |
|
|
|