Introduction to ECharts and getting started

Learn what ECharts is, why to use it, and how to install it and render your first chart.

🎯 Introduction

By the end of this article, you will understand what ECharts is and why it is widely used for frontend data visualization. You will also install it in a Vue 3 project and build a simple bar chart.


🧱 What is ECharts?

ECharts is an open-source JavaScript charting library for data visualization. Originally developed by Baidu, it is now maintained by the Apache Software Foundation, hence its full name, Apache ECharts.

Its purpose is simple: turn raw data into charts that are easy to understand. For example, a bar chart can show weekly sales, while a pie chart can show where users come from, making the information behind the numbers immediately visible.

ECharts supports these common chart types:

  • Line, bar, pie, and scatter charts
  • Radar charts, maps, and heatmaps
  • Candlestick charts, graphs, and gauges
ECharts uses Canvas for rendering and also supports SVG. It includes optimizations for large datasets, such as progressive rendering and data sampling. As a beginner, you can treat it as a practical choice for presenting data in charts.

✨ Why choose ECharts?

Among the many charting libraries available, ECharts stands out for several reasons:

AdvantageDescription
Ready to useRender a chart with a single configuration object, without graphics programming knowledge
Many chart typesDozens of built-in types cover most application needs
Rich interactionsBuilt-in tooltips, interactive legends, and data zoom
Chinese documentationFull official documentation in Chinese makes it accessible to Chinese-speaking developers
Ongoing updatesVersion 6.0, released in 2025, introduced a new default theme and dark mode

🚀 Installing ECharts

This course uses Node.js v22.0.0 and ECharts 6.1.0. In a Vue 3 project created with Vite, run:

npm install echarts
An outdated Node.js version may cause installation to fail. Run node -v to check your version first. An LTS release is recommended.

🛠 Your first chart

Creating an ECharts chart takes three steps. Once you know this pattern, subsequent charts only require different configuration:

  1. Prepare a DOM container with an explicit width and height.
  2. Initialize a chart instance with echarts.init(container).
  3. Pass in the configuration with setOption(option) to render the chart.
views/SalesChart.vue
<template>
    <!-- Step 1: Prepare a container with a width and height -->
    <div ref="chartRef" class="chart"></div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import * as echarts from 'echarts';

const chartRef = ref(null);

onMounted(() => {
    // Step 2: Initialize the chart instance
    const chart = echarts.init(chartRef.value);

    // Step 3: Pass in the configuration
    chart.setOption({
        title: {
            text: 'Weekly sales',
        },
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                type: 'bar',
                data: [120, 200, 150, 80, 70],
            },
        ],
    });
});
</script>

<style scoped>
.chart {
    width: 100%;
    height: 400px;
}
</style>

Here is the live rendering of this code:

Open the page to see a bar chart with a title.

Two common pitfalls:
  1. Initialize the chart in onMounted or later, when the DOM container exists.
  2. Set the container height. A width alone leaves its height at 0, so the chart is invisible even though the code reports no errors.

❓ Questions and answers

Q1: Why is my chart invisible even though there are no console errors?

The container most likely has a height of 0. Check its height and whether a parent element is collapsing it.

Q2: Can I use ECharts in plain HTML or other frameworks?

Yes. ECharts has no framework dependencies and works with Vue, React, and plain JavaScript. This course uses Vue 3 throughout.

Q3: What does import * as echarts from 'echarts' mean?

It collects all exports from the echarts module into an object named echarts, which you can then access through methods such as echarts.init.


🧪 Practice

Modify the first chart above:

  1. Change the title to “Visitors this week”.
  2. Extend the horizontal axis to all seven days, Monday through Sunday, and provide your own data.
  3. Change the chart type from 'bar' to 'line' and observe the result.
views/VisitChart.vue
<template>
    <div ref="chartRef" class="chart"></div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import * as echarts from 'echarts';

const chartRef = ref(null);

onMounted(() => {
    const chart = echarts.init(chartRef.value);

    // Write your code here
});
</script>

<style scoped>
.chart {
    width: 100%;
    height: 400px;
}
</style>

🎉 You have created your first data visualization! Next, we will break down the configuration object passed to setOption and explain what each part controls.