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 | |||
					Loading…
					
					
				
		Reference in new issue