echarts uses dashboard graphs to display percentages

echarts case: Dashboard chart showing percentage style

In actual development work, data visualization is often used . echarts is a more commonly used data visualization tool. Let me share a case of echarts dashboard chart showing percentage style . The renderings are as follows:

 Dashboard chart display percentage style

Proceed as follows:

1. Download and import echarts

npm install echarts --save

Introduce in the required js file using echarts

import echarts from 'echarts'

2. Get the dom element and create an option

let ginsengGauge = echarts.init(document.getElementById('ginsengGauge'))
let option ={
    
    
	 tooltip: {
    
    
      formatter: '{a} <br/>{b} : {c}%'
    },
    series: [
    	{
    
    
        type: 'gauge',  //类型:仪表盘图
        name: '制造业', 
        title: {
    
    
          offsetCenter: [0, '120%'],  //系列标题文字(效果图中的“制造业”)的位置,第一个为横坐标,第二个为纵坐标
          color: "#fff",  //字体颜色
          fontSize: 16,
        },

        center: ['15%', '45%'],   //仪表盘图的中心点相对于dom容器的位置
        detail: {
    
      //设置效果图中文字“30.25%”的相关配置
          formatter: '{value}%',
          offsetCenter: [0, 0],
          color: "#FFF",
          fontSize: 18
        },
        data: [{
    
    
          value: 30.25, //此处要改数据
          name: '制造业'
        }],
        radius: '50%',  //环形的大小
        clockwise: true,
        axisLine: {
    
    
          show: true,
          lineStyle: {
    
    
            color: [
              [0.3025, '#1A8FC5'], //占总数的30.25%,即value/100,颜色为'#1A8FC5'
              [1, '#E1E8EE']  //基底大圈比例为1,颜色为'#E1E8EE',
            ],
            width: 10,  //环形的粗细
          }
        },
        splitLine: {
    
    
          show: false   //不显示分隔线
        },
        axisTick: {
    
    
          show: false  //不显示仪表盘刻度
        },
        axisLabel: {
    
    
          show: false
        },
        pointer: {
    
    
          show: false  //不显示仪表盘指针
        },
      },
    ]
}

Welcome to the personal blog Song Zhang

Guess you like

Origin blog.csdn.net/weixin_47160442/article/details/112601455