Detailed configuration process of Echarts pie chart


Introduction to pie charts

Echarts pie chart is a commonly used chart type in Echarts and a commonly used form in data visualization. Pie charts display the ratio and proportion of data in a sector-shaped manner.

The characteristics of Echarts pie charts are as follows:

  1. Intuitive display of data proportions: Pie charts use sectors of different sizes to represent data proportions and proportion relationships, intuitively showing the distribution of data. Pie charts are suitable for showing relative proportions and part-to-whole data.

  2. Various style configurations: Echarts pie charts provide a wealth of style configuration options. You can customize the color of the sector, the inner and outer radius, the label style, etc., as well as the title, legend, etc. of the entire chart, making the chart more personalized.

  3. Rich interactive operations: Echarts pie charts support interactive operations such as selection, highlighting, and click events. Users can interact with pie charts to filter and view data.

  4. Animation effects: Echarts can add animation effects to pie charts, so that the charts present a smooth transition effect when loading or data is updated, enhancing the user's visual experience.

  5. Strong compatibility: Echarts pie charts are compatible with mainstream browsers, and provide responsive layout functions that can adapt to different screen sizes.

  6. Good scalability: Echarts provides a wealth of extension plug-ins and themes, and users can customize the functions and appearance of charts according to their needs. At the same time, Echarts also supports integration with other front-end frameworks (such as Vue, React) to facilitate developers to better use and expand.

In short, Echarts pie chart is a powerful, flexible, and interactive data visualization tool that can effectively display the proportion and proportion of data. Whether it is a simple data distribution chart or a complex data analysis chart, Echarts pie chart can meet the needs of users.

Configuration steps

The detailed configuration process of Echarts pie chart is as follows:

  1. Introduce the Echarts library: Introduce the JavaScript file of the Echarts library into the HTML file.
<script src="echarts.min.js"></script>
  1. Creates a DOM container with specified width and height for displaying a pie chart.
<div id="chart" style="width: 600px; height: 400px;"></div>
  1. Initialize the echarts instance and bind it to the specified DOM container.
var chart = echarts.init(document.getElementById('chart'));
  1. Configure related parameters of the pie chart:
var option = {
    
    
  title: {
    
    
    text: '饼图示例',   // 图表标题
    x: 'center'   // 标题位置
  },
  series: [{
    
    
    type: 'pie',   // 图表类型为饼图
    radius: '50%',   // 饼图半径
    data: [
      {
    
    value: 335, name: '苹果'},   // 数据项
      {
    
    value: 310, name: '香蕉'},
      {
    
    value: 234, name: '橙子'},
      {
    
    value: 135, name: '葡萄'},
      {
    
    value: 1548, name: '西瓜'}
    ]
  }]
};
  1. Apply the configuration to the pie chart and display it.
chart.setOption(option);

The above is a simple pie chart configuration process. More configurations can be performed according to needs, such as adding legends, setting fan colors, setting label styles, etc. For detailed configuration options, please refer to Echarts official documentation.

Simple example

Here's an example showing a simple pie chart:

<!DOCTYPE html>
<html>
<head>
  <title>Echarts饼图示例</title>
  <script src="echarts.min.js"></script>
</head>
<body>
  <div id="chart" style="width: 600px; height: 400px;"></div>
  <script>
    var chart = echarts.init(document.getElementById('chart'));
    var option = {
      
      
      title: {
      
      
        text: '饼图示例',
        x: 'center'
      },
      series: [{
      
      
        type: 'pie',
        radius: '50%',
        data: [
          {
      
      value: 335, name: '苹果'},
          {
      
      value: 310, name: '香蕉'},
          {
      
      value: 234, name: '橙子'},
          {
      
      value: 135, name: '葡萄'},
          {
      
      value: 1548, name: '西瓜'}
        ]
      }]
    };
    chart.setOption(option);
  </script>
</body>
</html>

The above code will display a pie chart with a width of 600px and a height of 400px on the page. The chart title is "Pie Chart Example". The radius of the pie chart is 50%. The sectors represent the data of apples, bananas, oranges, grapes, and watermelons respectively. The specific effect is shown in the figure below.
Insert image description here

Guess you like

Origin blog.csdn.net/m0_62617719/article/details/132910127