Vue implements the method of displaying percentage of echart pie chart legend

Vue implements the method of displaying percentage of echart pie chart legend

This article mainly introduces the pie chart data part of Vue using echart to display percentages, and shares it with everyone. The details are as follows:

Rendering

insert image description here

Implementation source code

option = {
    title : {
        text: 'Source of user access to a certain site',
        subtext: 'Purely fictitious',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical', // Layout mode, the default is horizontal layout, optional: 'horizontal' ¦ 'vertical'
         // Horizontal placement, default is on the left, options are: 'center' | 'left' | 'right' | {number} (x coordinate, unit px)
        x: 'left',
        // Vertical placement, default is the top of the whole image, options are: 'top' | 'bottom' | 'center' | {number} (y coordinate, unit px)
        y: 'bottom',
        // Rewrite the legend display style formatter: function(name) {
              // Get the legend display content let data = option.series[0].data;
              let total = 0;
              let tarValue = 0;
              for (let i = 0, l = data.length; i < l; i++) {
                  total += data[i].value;
                  if (data[i].name == name) {
                      tarValue = data[i].value;
                  }
              }
              let p = (tarValue / total * 100).toFixed(2);
              return name + ' ' + ' ' + p + '%';
          },
        data: ['Direct access', 'Email marketing', 'Affiliate advertising', 'Video advertising', 'Search engine']
    },
    series: [
        {
            name: 'Access source',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[
                {value:335, name:'Direct access'},
                {value:310, name:'Email Marketing'},
                {value:234, name:'Alliance Advertising'},
                {value:135, name:'Video Ad'},
                {value:1548, name:'search engine'}
            ],
            itemStyle: {
                emphasis:
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};

This is the end of this article about how to use Vue to implement echart pie chart legend to display percentages. For more information about Vue pie chart display percentages, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • vue+highcharts to achieve 3D pie chart effect
  • Vue uses ECharts to implement line charts and pie charts
  • Reference Antv G2 in the vue project, taking the pie chart as an example
  • How to draw 3d pie chart using highCharts in Vue
  • Vue uses Highcharts to implement 3D pie chart

<<:  A brief understanding of MySQL storage field type query efficiency

>>:  Detailed explanation of Docker data backup and recovery process

Recommend

Common front-end JavaScript method encapsulation

Table of contents 1. Enter a value and return its...

A brief discussion on React native APP updates

Table of contents App Update Process Rough flow c...

MySQL 5.7 installation and configuration tutorial under CentOS7 (YUM)

Installation environment: CentOS7 64-bit, MySQL5....

A simple method to modify the size of Nginx uploaded files

Original link: https://vien.tech/article/138 Pref...

XHTML Getting Started Tutorial: Commonly Used XHTML Tags

<br />Just like an article, our web pages sh...

MySQL 5.7 installation and configuration method graphic tutorial

This tutorial shares the installation and configu...

About using Alibaba's iconfont vector icon in Vue

There are many import methods on the Internet, an...

Sample code for html list box, text field, and file field

Drop-down box, text field, file field The upper p...

MySQL 5.7.23 decompression version installation tutorial with pictures and text

It is too troublesome to find the installation tu...

Front-end state management (Part 2)

Table of contents 1. Redux 1.1. Store (librarian)...

Some Linux file permission management methods you may not know

Why do we need permission management? 1. Computer...

Two ways to visualize ClickHouse data using Apache Superset

Apache Superset is a powerful BI tool that provid...

Vue+element ui realizes anchor positioning

This article example shares the specific code of ...

How a select statement is executed in MySQL

Table of contents 1. Analyzing MySQL from a macro...