Introduction to ECharts and getting started
🎯 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
✨ Why choose ECharts?
Among the many charting libraries available, ECharts stands out for several reasons:
| Advantage | Description |
|---|---|
| Ready to use | Render a chart with a single configuration object, without graphics programming knowledge |
| Many chart types | Dozens of built-in types cover most application needs |
| Rich interactions | Built-in tooltips, interactive legends, and data zoom |
| Chinese documentation | Full official documentation in Chinese makes it accessible to Chinese-speaking developers |
| Ongoing updates | Version 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
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:
- Prepare a DOM container with an explicit width and height.
- Initialize a chart instance with
echarts.init(container). - Pass in the configuration with
setOption(option)to render the chart.
<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.
- Initialize the chart in
onMountedor later, when the DOM container exists. - 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:
- Change the title to “Visitors this week”.
- Extend the horizontal axis to all seven days, Monday through Sunday, and provide your own data.
- Change the chart
typefrom'bar'to'line'and observe the result.
<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.
