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

How to use polar coordinate system to display data in ECharts

WBOY
Release: 2023-12-18 13:58:46
Original
1068 people have browsed it

How to use polar coordinate system to display data in ECharts

How to use polar coordinate system to display data in ECharts

1. Introduction
ECharts is an open source visualization library developed based on JavaScript, which provides a wealth of The chart types and interactive capabilities make it easy to visually display data. Among them, polar coordinate system is a type of coordinate system commonly used in ECharts. It can display data in polar coordinates, making the relationship between data clearer. This article will introduce how to use the polar coordinate system to display data in ECharts, and provide some specific code examples.

2. Basic configuration
Before using ECharts to display polar coordinate system data, we first need to perform some basic configuration. In the tag of the HTML page, introduce the JavaScript file of ECharts:

<script src="echarts.min.js"></script>
Copy after login

Then, add a <div># with a certain width and height to the page. ##Element, used to accommodate ECharts charts:

<div id="chart" style="width: 600px; height: 400px;"></div>
Copy after login

Next, we need to create an ECharts instance in the JavaScript code and obtain the corresponding DOM element:

var chart = echarts.init(document.getElementById('chart'));
Copy after login

3. Data preparation

Before displaying polar coordinate system data, we need to prepare the data to be displayed. Suppose we have a set of two-dimensional data. Each data consists of two values: angle and radius. It can be saved using the following data structure:

var data = [
  [10, 50],
  [45, 80],
  [90, 70],
  // ...
];
Copy after login

4. Use the polar coordinate system to display the data

Next, We can use the
polar configuration item provided by ECharts to define a polar coordinate system. After initializing the ECharts instance, we can configure the relevant style and content of the chart by calling the setOption method:

chart.setOption({
  polar: {},
  series: [{
    type: 'scatter',
    coordinateSystem: 'polar',
    data: data
  }]
});
Copy after login

Among them, the value of the

polar configuration item is an empty object {}, means we use the default polar coordinate system settings. seriesThe configuration item is used to configure the series type used by the chart. Here we use 'scatter'scatter chart series to display data. The value of the coordinateSystem configuration item is 'polar', indicating that the series uses the polar coordinate system to display data. dataThe configuration item is the data prepared previously.

5. Customized style

In addition to the basic polar coordinate system configuration, we can also customize the style of the chart. The following are some commonly used custom configuration examples:

    Adjust the radius range of the polar coordinate system:
  1. polar: {
      radius: ['20%', '80%']
    }
    Copy after login
    Add axes and scales:
  1. polar: {
      radiusAxis: {
        show: true,
        splitLine: {
          show: true
        },
        axisLine: {
          show: true
        }
      },
      angleAxis: {
        show: true,
        splitLine: {
          show: true
        },
        axisLine: {
          show: true
        }
      }
    }
    Copy after login
    Customize the style of scatter plot:
  1. series: [{
      type: 'scatter',
      coordinateSystem: 'polar',
      data: data,
      symbol: 'circle',
      symbolSize: 10,
      itemStyle: {
        color: '#ff0000'
      }
    }]
    Copy after login
    6. Summary

    This article introduces how to use the polar coordinate system to display data in ECharts, and provides some Specific code examples. I hope that through the introduction of this article, readers can master how to configure and use the polar coordinate system, and set custom styles according to actual needs. For more detailed configuration options, please refer to the ECharts official documentation.

    The above is the detailed content of How to use polar coordinate system to display data in ECharts. 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