Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw pie chart and ring chart with ECharts

Shulou Source: shulou.com Published: 2022-06-03 03:36:06 09月16日 Update

This article mainly introduces "how to use ECharts to draw pie chart and ring chart". In daily operation, I believe many people have doubts about how to use ECharts to draw pie chart and ring chart. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to draw pie chart and ring chart with ECharts". Next, please follow the editor to study!

Let's make a basic pie chart and set the type parameter value of series in Echarts to pie, as shown in figure 4-14.

The code is as follows:

Option = {title: {text: 'proportion of sales volume of each commodity', subtext: 'analysis of the situation in A store', left: 'center'}, tooltip: {trigger:' item', formatter:'{a} {b}: {c} ({d}%)'}, legend: {orient: 'vertical' Left: 'left', data: [' A goods','B goods','C goods','D goods','E goods']}, series: [{name: 'goods sold', type: 'pie', data: [{value: 343 Name:'A Commodity'}, {value: 250, name:'B Commodity'}, {value: 509, name:'C Commodity'}, {value: 108, name:'D Commodity'}, {value: 948, name:'e Commodity'}],}]}

▲ figure 4-14 pie chart

In the above code, legend is set to vertical to avoid overlap with the title when displayed horizontally. Here, the display format of tooltip is set to: formatter:'{a}

{b}: {c} ({d}%)', the specific meanings of the parameters in the pie chart are: {a} (series name), {b} (data item name), {c} (numerical value), {d} (percentage). When the mouse hovers over a piece of cake, the piece of cake is highlighted and text and values are displayed in formatter format.

It should be noted that when we click on the legend of the pie chart, such as clicking on the legend of C goods, the legend of C goods will turn gray, at the same time, the pie blocks of C goods will no longer be displayed in the pie chart, and the percentage will be recalculated, as shown in figure 4-15.

▲ figure 4-15 pie chart display control

In addition to the basic pie chart, we often use a ring chart. In ECharts, add the radius parameter to series to draw a ring graph, such as radius in the following code: ['50% radius,'70%'], which represents the proportion of the inner radius and the outer radius of the ring is 50% and 70%, respectively.

Option = {title: {text: 'proportion of sales volume of each commodity', subtext: 'analysis of the situation in A store', left: 'center'}, tooltip: {trigger:' item', formatter:'{a} {b}: {c} ({d}%)'}, legend: {orient: 'vertical' Left: 'left', data: [' A merchandise','B merchandise','C merchandise','D merchandise','E merchandise']}, series: [{name: 'goods sold', type: 'pie', radius: [' 50%','70%'] Data: [{value: 343, name:'A Commodity'}, {value: 250, name:'B Commodity'}, {value: 509, name:'C Commodity'}, {value: 108, name:'d Commodity'}, {value: 948 Name:'e goods'}],}]}

The visualization result of the ring diagram is shown in figure 4-16.

▲ figure 4-16 ring chart

At this point, the study on "how to draw pie chart and ring chart with ECharts" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Goods rings learning code parameters such as figure radius name mall situation numerical value more format percentage percentage sales volume analysis help utility next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL Shulou Technology Linux Shulou Information