Home > Web Front-end > JS Tutorial > body text

ECharts Water Polo Chart: How to display data proportion and goal completion

WBOY
Release: 2023-12-18 15:39:55
Original
1366 people have browsed it

ECharts Water Polo Chart: How to display data proportion and goal completion

ECharts Water Polo Chart: How to display data proportion and goal completion

Introduction:
In the field of data visualization, the water polo chart is a commonly used chart type , can visually display the proportion of data and the achievement of goals. ECharts is a powerful data visualization library that provides a wealth of chart types for developers to choose from. This article will introduce in detail how to use ECharts to create a water polo chart and display data proportions and goal completion, and provide specific code examples.

1. What is a water polo diagram?
The water polo chart is a special donut chart that uses the size of the donut to represent the proportion of data, and adds a solid circle inside the donut to represent the completion of the goal. Water polo charts are usually used to display data such as percentages and progress. It visually reflects the gap between data and goals.

2. Use ECharts to create a water polo chart

  1. Introduce the ECharts library
    First, introduce the ECharts library into the project, which can be introduced by directly downloading the source code or using CDN . For example:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.1.0/echarts.min.js"></script>
    Copy after login
  2. Create container
    Create a container in HTML to display the water polo diagram, for example:

    <div id="waterball-chart" style="width: 400px; height: 400px;"></div>
    Copy after login
  3. Write JavaScript code
    Use ECharts to create a water polo chart through JavaScript code and configure related parameters. The following is a sample code:

    // 初始化ECharts实例
    var myChart = echarts.init(document.getElementById('waterball-chart'));
    
    // 指定图表的配置项和数据
    var option = {
     series: [{
         type: 'liquidFill',
         data: [0.6], // 数据占比,范围为[0,1]
         shape: 'circle',
         outline: {
             show: false
         },
         backgroundStyle: {
             color: '#FFA500'
         },
         label: {
             show: true,
             position: ['50%', '50%'],
             formatter: function(value) {
                 return Math.round(value * 100) + '%'; // 格式化显示百分比
             },
             fontSize: 32,
             fontWeight: 'bold'
         },
         itemStyle: {
             color: '#FF4500'
         },
         emphasis: {
             itemStyle: {
                 color: '#FF0000'
             }
         }
     }]
    };
    
    // 使用刚指定的配置项和数据显示图表
    myChart.setOption(option);
    Copy after login
  4. Rendering chart
    Apply configuration items to the water polo chart by calling the setOption method and render it. For example:

    myChart.setOption(option);
    Copy after login

3. Code analysis
In the above example code, we created a water polo chart through the liquidFill type of ECharts. Among them, the configuration item series is used to configure the style, data and other information of the water polo chart. The

  • data field indicates the data proportion, and the value range is [0,1]. In the example, the data proportion is 0.6, which is 60%. The
  • shape field indicates the shape of the water polo diagram, which can be set to circle (circle) or rect (rectangle). The
  • outline field indicates whether to display the outline of the water polo diagram, which is set to not be displayed here. The
  • backgroundStyle field indicates the background style of the water polo diagram. In the example, the color is orange (#FFA500). The
  • label field represents the text label displayed in the water polo diagram, by setting parameters such as show, position, formatter, etc. Control the display position and format of labels. The
  • itemStyle field represents the fill style of the water polo diagram. In the example, the color is orange-red (#FF4500). The
  • emphasis field indicates the highlight style of the water polo chart. In the example, the highlight color is red (#FF0000).

By modifying the values ​​of these configuration items, you can create and customize water polo charts according to your own needs.

Conclusion:
This article introduces in detail how to use ECharts to create a water polo chart, and shows the data proportion and goal completion. Through simple code examples, I hope readers can quickly get started using ECharts to draw water polo diagrams and customize them according to actual needs. ECharts is a powerful and easy-to-use data visualization library that can help developers better display and understand data. Try using ECharts to create a water polo chart to make your data visualization more vivid and interesting!

Reference link:

  • ECharts official document: https://echarts.apache.org/zh/index.html
  • ECharts official example: https:/ /echarts.apache.org/examples/zh/index.html

The above is the detailed content of ECharts Water Polo Chart: How to display data proportion and goal completion. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template