Detailed configuration process of Echarts sunburst chart


Introduction to the Rising Sun Chart

Echarts sunburst chart is a data visualization chart type used to display the distribution of hierarchical relationship data. The sunburst chart expresses the hierarchy and size relationship of data through different annular areas and fan-shaped areas, thereby forming the shape of a sun, hence the name sunburst chart.

The characteristics of Echarts sunburst chart are as follows:

  1. Hierarchical structure display: The sunburst chart is suitable for displaying hierarchical structure data, and represents different levels of data through different sector areas. The size and position of each sector represents the size and hierarchical relationship of the data.

  2. Progressive presentation: The sunburst chart supports progressive presentation, which can gradually expand or contract each hierarchical structure through interactive operations, allowing users to gain a deeper understanding of the details of the data.

  3. Encoding multiple dimensions: Sunburst charts can encode data in multiple dimensions, representing different dimensions of data through the color, radius, or angle of the sector area. This allows multiple dimensions of data to be displayed simultaneously in one chart, making it easier to compare and analyze data.

  4. Rich interactive operations: Echarts sunburst chart supports interactive operations such as selection, highlighting, and click events. Users can interact with the sunburst chart to filter and view data. For example, you can expand or contract the sub-level data of that level by clicking on a sector area.

  5. Strong compatibility: Echarts sunburst chart is compatible with mainstream browsers, and provides a responsive layout function 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 sunburst chart is a powerful, flexible, and interactive data visualization tool that can effectively display the distribution and relationship of hierarchical data. Through the sunburst chart, users can more intuitively understand the hierarchical structure and size relationship of data, thereby making more accurate data analysis and decisions.

Configuration process

The detailed configuration process of Echarts sunburst 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 a specified width and height for displaying the sunburst 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 the relevant parameters of the sunburst chart:
var option = {
    
    
  title: {
    
    
    text: '旭日图示例',   // 图表标题
    x: 'center'   // 标题位置
  },
  tooltip: {
    
    },   // 鼠标悬浮时的提示框配置
  series: [{
    
    
    name: '旭日图',   // 数据系列的名称
    type: 'sunburst',   // 图表类型为旭日图
    data: [
      {
    
    
        name: 'A',   // 数据项的名称
        children: [
          {
    
     name: 'A1', value: 10 },   // 子层次数据项的名称和数值
          {
    
     name: 'A2', value: 20 }
        ]
      },
      {
    
    
        name: 'B',
        children: [
          {
    
     name: 'B1', value: 15 },
          {
    
     name: 'B2', value: 25 }
        ]
      }
    ]
  }]
};
  1. Apply the configuration to the sunburst chart and display it.
chart.setOption(option);

The above is a simple sunburst chart configuration process. You can perform more configurations according to your needs, such as setting the color of the chart, adjusting the style of the chart, adding interactive operations, etc. For detailed configuration options, please refer to Echarts official documentation.

Simple example

Here's an example showing a simple sunburst 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'
      },
      tooltip: {
      
      },
      series: [{
      
      
        name: '旭日图',
        type: 'sunburst',
        data: [
          {
      
      
            name: 'A',
            children: [
              {
      
       name: 'A1', value: 10 },
              {
      
       name: 'A2', value: 20 }
            ]
          },
          {
      
      
            name: 'B',
            children: [
              {
      
       name: 'B1', value: 15 },
              {
      
       name: 'B2', value: 25 }
            ]
          }
        ]
      }]
    };
    chart.setOption(option);
  </script>
</body>
</html>

The above code will display a sunburst chart with a width of 600px and a height of 400px on the page. The chart title is "Sunburst Chart Example", which shows two levels of data. There are two sub-levels of data under each level, and each data Each item has a corresponding value, and the effect diagram is as shown below.
Insert image description here

You can modify the data and configuration options to create sunburst charts with different styles and functions according to your own needs.

Guess you like

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