• Home
  • About
    • Anpu Li photo

      Anpu Li

      This is Anpu Li's personal website.

    • Learn More
    • Email
    • LinkedIn
    • Instagram
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

A Comprehensive Guide to Visualization Using ECharts

17 Dec 2019

Reading time ~2 minutes

This is a comprehensive step-by-step tutorial on how to visualize data with ECharts. Special thinks to Wenhe Li for the help in website building.

Live Demo of a P2P default geomap: link

  • Installation & Setup
    • Install node.js
    • Install ECharts
  • Build Your First Visualization: Bar
    • Prepare html file
    • Prepare js file
    • Build
  • Geomap

Installation & Setup

Install node.js

Please go to the download page of the official website and follow the instructions.

Install ECharts

First, make a new directory where you want to put your visualization in.

mkdir echarts-vis
cd echarts-vis

Second, make a new file called package.json and copy the following in the file. Please ignore the meaning for now if you don’t understand what this does. Save and close the file.

{
    "scripts": {
        "start": "npx parcel index.html"
    }
}

Third, run the following command

npm install --save echarts
npm install --save-dev parcel

Build Your First Visualization: Bar

This section will walk you through a simple bar graph.

image

Prepare html file

Create a new file index.html. Copy the following content inside

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>
<body>
    <!-- Prepare a Dom for ECharts -->
    <div id="main" style="width: 600px;height:400px;"></div>

    <script src="index.js"></script>
</body>
</html>

Prepare js file

Create a new file index.js

import * as echarts from "echarts";

// based on the prepared dom, initiate an echarts instance
var myChart = echarts.init(document.getElementById('main'));

// specify configuration and data
var option = {
    title: {
        text: 'ECharts Demo'
    },
    tooltip: {},
    legend: {
        data:['Sales']
    },
    xAxis: {
        data: ["Shirts","Cardigan","Sweater","Pants","High Heels","Socks"]
    },
    yAxis: {},
    series: [{
        name: 'Sales',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
    }]
};

// Use the config and data set above to show the graph
myChart.setOption(option);

Build

Please run

npm run start

Wait a few moments and you should see

image

You can can open http://localhost:1234 and play with the interaction.

Geomap



echartsvisualizationP2Pheatmapjavascriptsnpmparcel Share Tweet +1