What is echarts?
ECharts is a powerful, interactive charting and visualization library for browser environments. It provides a wide range of chart types and is highly customizable, making it suitable for complex data visualization needs.
What are echarts's main functionalities?
Line Chart
This code initializes a basic line chart with ECharts. It sets up the x-axis with categories representing days of the week and the y-axis with numerical values. The series data represents the values for each day.
const echarts = require('echarts');
const chart = echarts.init(document.getElementById('main'));
const option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}]
};
chart.setOption(option);
Bar Chart
This code initializes a basic bar chart with ECharts. Similar to the line chart, it sets up the x-axis with categories and the y-axis with numerical values. The series data represents the bar heights for each category.
const echarts = require('echarts');
const chart = echarts.init(document.getElementById('main'));
const option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar'
}]
};
chart.setOption(option);
Pie Chart
This code initializes a basic pie chart with ECharts. The series data represents different categories and their corresponding values, which are displayed as slices of the pie.
const echarts = require('echarts');
const chart = echarts.init(document.getElementById('main'));
const option = {
series: [{
type: 'pie',
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
}]
};
chart.setOption(option);
Other packages similar to echarts
chart.js
Chart.js is a simple yet flexible JavaScript charting library for designers & developers. It offers a variety of chart types and is known for its ease of use and integration. Compared to ECharts, Chart.js is more lightweight but may lack some of the advanced features and customizability.
highcharts
Highcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to web sites or web applications. Highcharts is known for its extensive range of chart types and high level of customization. It is comparable to ECharts in terms of functionality but is a commercial product with licensing fees for certain uses.
d3
D3.js is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It uses SVG, HTML, and CSS. D3 is highly flexible and powerful, allowing for complex and custom visualizations. However, it has a steeper learning curve compared to ECharts.
ECharts
Introduction
ECharts is a free, powerful charting and visualization library offering an easy way of adding intuitive, interactive, and highly customizable charts to your commercial products. It is written in pure JavaScript and based on zrender, which is a whole new lightweight canvas library.
Installation
npm/webpack
$ npm i echarts --save
import echarts from 'echarts';
import 'echarts/chart/bar';
import 'echarts/chart/pie';
let mychart = echarts.init(dom, null, { renderer: 'canvas' });
mychart.setOption({ ... });
or
import echarts from 'echarts/dist/echarts';
let mychart = echarts.init(dom, null, { renderer: 'canvas' });
mychart.setOption({ ... });
Examples
Docs
We will release the English doc soon:)
License
Copyright (c) 2013, Baidu Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.