‘lijianhao’
3 years ago
4 changed files with 188 additions and 19 deletions
@ -0,0 +1,110 @@ |
|||||
|
import React from 'react' |
||||
|
import { useEffect, useRef } from 'react'; |
||||
|
import * as echarts from 'echarts'; |
||||
|
|
||||
|
const PieChart = (props) => { |
||||
|
|
||||
|
const { width, height, data, colorList, underColorList, total, text } = props |
||||
|
|
||||
|
const chartRef = useRef(null); |
||||
|
let name = [], emptyName = [] |
||||
|
// const name = data?.map(d)
|
||||
|
data?.forEach(d => { |
||||
|
name.push(d.name) |
||||
|
emptyName.push({ |
||||
|
name: '', |
||||
|
value: d.value |
||||
|
}) |
||||
|
}) |
||||
|
useEffect(() => { |
||||
|
let chartInstance = echarts.init(chartRef.current); |
||||
|
const option = { |
||||
|
tooltip: { |
||||
|
trigger: "item", |
||||
|
}, |
||||
|
legend: { |
||||
|
orient: "vertical", |
||||
|
itemWidth: 10, |
||||
|
itemHeight: 10, |
||||
|
right: '30%', |
||||
|
top: 'center', |
||||
|
align: 'left', |
||||
|
data: name, |
||||
|
textStyle: { |
||||
|
color: "#fff", |
||||
|
}, |
||||
|
}, |
||||
|
grid: { |
||||
|
left: '10%' |
||||
|
}, |
||||
|
// title: [
|
||||
|
// {
|
||||
|
// text: text,
|
||||
|
// top: "58%",
|
||||
|
// left: '16%',
|
||||
|
// textStyle: {
|
||||
|
// color: "#E9F7FF",
|
||||
|
// fontSize: 14,
|
||||
|
// },
|
||||
|
// },
|
||||
|
// {
|
||||
|
// text: total,
|
||||
|
// top: "40%",
|
||||
|
// left: '10%',
|
||||
|
// textStyle: {
|
||||
|
// fontSize: "30",
|
||||
|
// color: "#FFFFFF",
|
||||
|
// fontFamily: "YouSheBiaoTiHei",
|
||||
|
// },
|
||||
|
// },
|
||||
|
// ],
|
||||
|
series: [ |
||||
|
{ |
||||
|
name: "底层背景", |
||||
|
type: "pie", |
||||
|
hoverAnimation: false, |
||||
|
legendHoverLink: false, |
||||
|
radius: ["60%", "72%"], |
||||
|
center: ['25%', '50%'], |
||||
|
color: underColorList, |
||||
|
label: { |
||||
|
show: false |
||||
|
}, |
||||
|
labelLine: { |
||||
|
show: false |
||||
|
}, |
||||
|
tooltip: { |
||||
|
show: false, |
||||
|
}, |
||||
|
|
||||
|
data: emptyName, |
||||
|
}, |
||||
|
{ |
||||
|
name: "已绿化里程统计", |
||||
|
type: "pie", |
||||
|
radius: ["67%", "80%"], |
||||
|
center: ['25%', '50%'], |
||||
|
color: colorList, |
||||
|
label: { |
||||
|
show: false |
||||
|
}, |
||||
|
data: data, |
||||
|
}, |
||||
|
], |
||||
|
}; |
||||
|
|
||||
|
chartInstance.setOption(option); |
||||
|
window.addEventListener('resize', () => { |
||||
|
if (chartInstance) { |
||||
|
chartInstance.resize() |
||||
|
} |
||||
|
}) |
||||
|
}, []) |
||||
|
return ( |
||||
|
<div style={{ width: width || '100%', height: height || '100%' }}> |
||||
|
<div ref={chartRef} style={{ width: '100%', height: '100%' }}></div> |
||||
|
</div> |
||||
|
|
||||
|
) |
||||
|
} |
||||
|
export default PieChart |
@ -1,14 +1,39 @@ |
|||||
import React from 'react' |
import React from 'react' |
||||
import Module from '../../../public/module' |
import Module from '../../../public/module' |
||||
|
import PieChart from '../chart/pie-chart'; |
||||
|
|
||||
|
let data = [ |
||||
|
{ value: 435, name: "县道" }, |
||||
|
{ value: 679, name: "乡道" }, |
||||
|
{ value: 848, name: "村道" }, |
||||
|
] |
||||
|
let colorList = [ |
||||
|
"rgba(7,185,254,1)", |
||||
|
"rgba(28,96,254,1)", |
||||
|
"rgba(4,251,240,1)", |
||||
|
] |
||||
|
let underColorList = [ |
||||
|
"rgba(7,185,254,0.5)", |
||||
|
"rgba(28,96,254,0.5)", |
||||
|
"rgba(4,251,240,0.5)", |
||||
|
] |
||||
const LeftBottom = () => { |
const LeftBottom = () => { |
||||
const style = { height: "31%", marginTop: "3%" } |
const style = { height: "31%", marginTop: "3%" } |
||||
return ( |
return ( |
||||
<> |
<> |
||||
<Module style={style} title={"已绿化里程统计"}> |
<Module style={style} title={"已绿化里程统计"}> |
||||
|
{/* <div ref = {chartRef} style={{ width: '100%', height: '100%' }}></div> */} |
||||
</Module> |
<PieChart |
||||
</> |
data={data} |
||||
|
width='100%' |
||||
|
height='100%' |
||||
|
text='已绿化里程' |
||||
|
total={2344.13} |
||||
|
colorList={colorList} |
||||
|
underColorList={underColorList} |
||||
|
/> |
||||
|
</Module> |
||||
|
</> |
||||
) |
) |
||||
} |
} |
||||
export default LeftBottom |
export default LeftBottom |
@ -1,14 +1,42 @@ |
|||||
import React from 'react' |
import React from 'react' |
||||
import Module from '../../../public/module' |
import Module from '../../../public/module' |
||||
|
import PieChart from '../chart/pie-chart'; |
||||
|
|
||||
|
let data = [ |
||||
|
{ value: 435, name: "道路" }, |
||||
|
{ value: 679, name: "桥梁" }, |
||||
|
{ value: 848, name: "涵洞" }, |
||||
|
{ value: 666, name: "其他" }, |
||||
|
] |
||||
|
let colorList = [ |
||||
|
"rgba(7,185,254,1)", |
||||
|
"rgba(28,96,254,1)", |
||||
|
"rgba(4,251,240,1)", |
||||
|
"rgba(255,194,20,1)" |
||||
|
] |
||||
|
let underColorList = [ |
||||
|
"rgba(7,185,254,0.5)", |
||||
|
"rgba(28,96,254,0.5)", |
||||
|
"rgba(4,251,240,0.5)", |
||||
|
"rgba(255,194,20,0.5)" |
||||
|
] |
||||
const RightBottom = () => { |
const RightBottom = () => { |
||||
const style = { height: "31%", marginTop: "3%" } |
const style = { height: "31%", marginTop: "3%" } |
||||
return ( |
return ( |
||||
<> |
<> |
||||
<Module style={style} title={"养护完成情况"}> |
<Module style={style} title={"养护完成情况"}> |
||||
|
{/* <div ref = {chartRef} style={{ width: '100%', height: '100%' }}></div> */} |
||||
</Module> |
<PieChart |
||||
</> |
data={data} |
||||
|
width='100%' |
||||
|
height='100%' |
||||
|
text='养护总数' |
||||
|
total={2344.13} |
||||
|
colorList={colorList} |
||||
|
underColorList={underColorList} |
||||
|
/> |
||||
|
</Module> |
||||
|
</> |
||||
) |
) |
||||
} |
} |
||||
export default RightBottom |
export default RightBottom |
Loading…
Reference in new issue