Home Web Front-end JS Tutorial How to make beautiful ECharts charts

How to make beautiful ECharts charts

Dec 17, 2023 am 10:43 AM
echarts chart production Beautiful chart design Create beautiful visualization charts

How to make beautiful ECharts charts

How to make beautiful ECharts charts, specific code examples are required

ECharts is a JavaScript-based open source visualization library that can be used to create rich charts and visualizations. It provides a wealth of chart types and interactive functions, suitable for data visualization needs in various fields. This article will introduce how to use ECharts to create beautiful charts and give specific code examples.

First, we need to introduce the ECharts library file. You can download the latest version of the library file from the ECharts official website (https://echarts.apache.org/zh/index.html) and then introduce it into the HTML page.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>漂亮的ECharts图表</title>
  <script src="echarts.min.js"></script>
</head>
<body>
  <div id="myChart" style="width: 600px; height: 400px;"></div>
  <script>
    // 在这里编写图表代码
  </script>
</body>
</html>
Copy after login

Next, we can write specific chart code in the <script> tag. Below is a simple example showing how to create a histogram.

var myChart = echarts.init(document.getElementById('myChart'));

// 指定图表的配置项和数据
var option = {
  title: {
    text: '柱状图示例'
  },
  xAxis: {
    data: ['A', 'B', 'C', 'D', 'E']
  },
  yAxis: {},
  series: [{
    name: '销量',
    type: 'bar',
    data: [5, 20, 36, 10, 10]
  }]
};

// 使用配置项显示图表
myChart.setOption(option);
Copy after login

In the above code, we first obtain a chart instance through the echarts.init method, and then set the configuration items and data of the chart through the setOption method. Configuration items can define the title of the chart, the data of the x-axis and y-axis, and the type and data of the series. Taking the above histogram as an example, we set the title of the chart to "Bar Chart Example" through the title configuration item, and set the x-axis data to [' through the xAxis configuration item A', 'B', 'C', 'D', 'E'], the series type is set to histogram through the series configuration item, and the histogram data is set to [5, 20, 36, 10, 10].

In addition to bar charts, ECharts also supports multiple chart types such as line charts, scatter charts, pie charts, and radar charts. Below are some common charting code examples.

Line chart example:

var myChart = echarts.init(document.getElementById('myChart'));

var option = {
  title: {
    text: '折线图示例'
  },
  xAxis: {
    data: ['A', 'B', 'C', 'D', 'E'],
    axisLabel: {
      rotate: 45 // 旋转x轴标签
    }
  },
  yAxis: {},
  series: [{
    name: '数据',
    type: 'line',
    data: [5, 20, 36, 10, 10]
  }]
};

myChart.setOption(option);
Copy after login

Pie chart example:

var myChart = echarts.init(document.getElementById('myChart'));

var option = {
  title: {
    text: '饼图示例'
  },
  series: [{
    name: '数据',
    type: 'pie',
    data: [
      {value: 5, name: 'A'},
      {value: 20, name: 'B'},
      {value: 36, name: 'C'},
      {value: 10, name: 'D'},
      {value: 10, name: 'E'}
    ]
  }]
};

myChart.setOption(option);
Copy after login

Radar chart example:

var myChart = echarts.init(document.getElementById('myChart'));

var option = {
  title: {
    text: '雷达图示例'
  },
  radar: {
    indicator: [
      {name: 'A', max: 10},
      {name: 'B', max: 10},
      {name: 'C', max: 10},
      {name: 'D', max: 10},
      {name: 'E', max: 10}
    ]
  },
  series: [{
    name: '数据',
    type: 'radar',
    data: [
      {value: [5, 8, 9, 7, 6], name: '数据1'},
      {value: [3, 6, 7, 5, 4], name: '数据2'}
    ]
  }]
};

myChart.setOption(option);
Copy after login

Through the above example code, we can according to different needs To create different types of charts, and beautify the style of the charts by adjusting configuration items, such as setting titles, axis styles, adding legends, etc.

To summarize, making a beautiful ECharts chart requires the following steps:

  1. Introduce the ECharts library file.
  2. Create a chart instance, usually using the echarts.init method to pass in an HTML element as a container.
  3. Set the configuration items and data of the chart, define the style of the chart and display data.
  4. Use the setOption method to apply the configuration item to the chart instance and display the chart.

By constantly trying and adjusting configuration items, you can create more beautiful and personalized ECharts charts. I wish you can realize the beautiful chart you imagined as soon as possible!

The above is the detailed content of How to make beautiful ECharts charts. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

Simple JavaScript functions are used to check if a date is valid. function isValidDate(s) { var bits = s.split('/'); var d = new Date(bits[2] '/' bits[1] '/' bits[0]); return !!(d && (d.getMonth() 1) == bits[1] && d.getDate() == Number(bits[0])); } //test var

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

This article discusses how to use jQuery to obtain and set the inner margin and margin values ​​of DOM elements, especially the specific locations of the outer margin and inner margins of the element. While it is possible to set the inner and outer margins of an element using CSS, getting accurate values ​​can be tricky. // set up $("div.header").css("margin","10px"); $("div.header").css("padding","10px"); You might think this code is

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

This article explores ten exceptional jQuery tabs and accordions. The key difference between tabs and accordions lies in how their content panels are displayed and hidden. Let's delve into these ten examples. Related articles: 10 jQuery Tab Plugins

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

Discover ten exceptional jQuery plugins to elevate your website's dynamism and visual appeal! This curated collection offers diverse functionalities, from image animation to interactive galleries. Let's explore these powerful tools: Related Posts: 1

HTTP Debugging with Node and http-console HTTP Debugging with Node and http-console Mar 01, 2025 am 01:37 AM

http-console is a Node module that gives you a command-line interface for executing HTTP commands. It’s great for debugging and seeing exactly what is going on with your HTTP requests, regardless of whether they’re made against a web server, web serv

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

The following jQuery code snippet can be used to add scrollbars when the div content exceeds the container element area. (No demonstration, please copy it directly to Firebug) //D = document //W = window //$ = jQuery var contentArea = $(this), wintop = contentArea.scrollTop(), docheight = $(D).height(), winheight = $(W).height(), divheight = $('#c

See all articles