Vue uses echart to customize labels and colors

Vue uses echart to customize labels and colors

This article example shares the specific code of Vue using echart to customize tags and colors for your reference. The specific content is as follows

Regular style


UI painting style effect


The detail is that the color of the small dot must be consistent with the color of the pie chart piece. This can be achieved using this code in versions before 5.0 (echarts version).

label:{
 formatter: params => {//●
       return (
               '{icon|▅}{name|' +params.name+ '}{value|' +
               params.value + '}'
           );
       },
       rich:
           icon:
               fontSize: 16
           },
           name: {
               fontSize: 16,
               padding: [0, 10, 0, 4],
           },
           value: {
               fontSize: 16,
           }
       },
}

But my project has some special effects that are only supported by 5.0, so I have to upgrade to 5.0, and then this color will not work. We need to find a solution to implement it, and this is how it was finally implemented. When assigning data, reassign the color of each label and assign the value of the pie chart color block.
There are two sets of data here because the percentage inside the pie chart is superimposed, which is what is circled by the basket.

Configuration items:

series: [
    {
      type: 'pie',
      radius: [0, '75%'],
      center: ['50%', '50%'],
      top:0,
      // roseType: 'radius',
      avoidLabelOverlap: true,
      // minShowLabelAngle: 0.6,
      startAngle: 0,
      label: {
        show:true,
        position: 'outer',
        alignTo: 'edge',
        //Another solution point normal: {
          formatter: params => {
            // formatColor(params.color)
            // color = params.color
              return (
                  '{icon|● }{name|' + params.name + '}'+'\n'+'{value|' +
                  params.value+'times' + '}'
              );
          },
          padding:[0,-40,25,-40],
          rich:
              icon:
                fontSize: 15,
              },
              name: {
                fontSize: 13,
                color: '#666666'
              },
              value: {
                fontSize: 12,
                color: 'rgba(0,0,0,0.35)'
              }
          }
        }
      },
      labelLine:{
        length:10,
        length2:70,
        smooth: false,
        lineStyle:{
          color:"rgba(0,0,0,0.15)"
        }
      },
      data: []
    },
    {
      name: '',
      type: 'pie',
      radius: [0, '75%'],
      center: ['50%', '50%'],
      data:[],
      top:0,
      // roseType: 'radius',
      avoidLabelOverlap: true,
      startAngle: 0,
      itemStyle: {
          normal: {
              label: {
                  show: true,
                  position: 'inner',
                  color:"#fff",
                  fontSize: 14,
                  align:"center",
                  formatter: function (p) { //Indicator line corresponds to text, percentage return p.percent + "%";
                  }
              },
          }
      }
    }
  ]

Reassignment:

//Get the color card and reassign it let colorArr = pieOption.color

 let seriesData = JSON.parse(JSON.stringify(this.orderServiceTimeLenData.output.value.rows))||[]
      let seriesData1 = JSON.parse(JSON.stringify(this.orderServiceTimeLenData.output.value.rows))||[]
      if(seriesData.length){
        seriesData.forEach((item,index)=>{
          item.name = item.typeStr
          item.value = item.num
          item.label = {color:colorArr[index]}
        })
        seriesData1.forEach((item,index)=>{
          item.name = item.typeStr
          item.value = item.num
        })
      }
return {legend: {data: seriesData}, series: [{data: seriesData},{data: seriesData1}]};

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue custom tags and single page multiple routing implementation code
  • Custom el-select drop-down box label function in el-form label in Vue
  • The src attribute of Vue custom tags cannot use relative paths
  • Example of tab switching effect implemented by Vue2.0 (content can be customized)
  • Detailed explanation of Vue-basic tags and custom controls

<<:  How to solve the high concurrency problem in MySQL database

>>:  How MySQL uses transactions

Recommend

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command mysql> ...

Detailed explanation of the difference between run/cmd/entrypoint in docker

In Dockerfile, run, cmd, and entrypoint can all b...

Html+CSS drawing triangle icon

Let’s take a look at the renderings first: XML/HT...

Mysql uses insert to insert multiple records to add data in batches

If you want to insert 5 records into table1, the ...

nuxt.js multiple environment variable configuration

Table of contents 1. Introduction 2. Scenario 3. ...

CSS3 gradient background compatibility issues

When we make a gradient background color, we will...

Detailed tutorial on docker-compose deployment and configuration of Jenkins

Docker-compose deployment configuration jenkins 1...

Let IE support CSS3 Media Query to achieve responsive web design

Today's screen resolutions range from as smal...

How to remount the data disk after initializing the system disk in Linux

Remount the data disk after initializing the syst...

N ways to align the last row of lists in CSS flex layout to the left (summary)

I would like to quote an article by Zhang Xinxu a...

MySQL Router implements MySQL read-write separation

Table of contents 1. Introduction 2. Configure My...

A brief discussion on Python's function knowledge

Table of contents Two major categories of functio...

How to set Nginx log printing post request parameters

【Foreword】 The SMS function of our project is to ...

jQuery implements shopping cart function

This article example shares the specific code of ...