console
window.onload = () => {
// 数据源是二维数组
var myChart = echarts.init(document.getElementById('main'));
var option = {
legend: {},
tooltip: {},
dataset: {
source: [
['product', '2015', '2016', '2017'],
['Matcha Latte', 43.3, 85.8, 93.7],
['Milk Tea', 83.1, 73.4, 55.1],
['Cheese Cocoa', 86.4, 65.2, 82.5],
['Walnut Brownie', 72.4, 53.9, 39.1],
]
},
xAxis: {
type: 'category', // 声明一个X轴,类目轴(category)。默认情况下,类目轴对应到 dataset 第一列
},
yAxis: {},
series: [ // 声明多个 bar 系列,默认情况下,每个系列会自动对应到 dataset 的每一列
{type: 'bar'},
{type: 'bar'},
{type: 'bar'},
]
};
myChart.setOption(option);
// 数据源是数组对象
var myChart2 = echarts.init(document.getElementById('main2'));
var option2 = {
legend: {},
tooltip: {},
dataset: {
// 指定维度名的顺序,从而可以利用默认的维度到坐标轴的映射
// 如果不指定 dimensions ,也可以通过指定 series.encode 完成映射
dimensions: ['product','2015','2016','2017'],
source: [
{product: 'Matcha Latte', '2015': 43.3, '2016': 85.8, '2017': 93.7},
{product: 'Milk Tea', '2015': 83.1, '2016': 73.4, '2017': 55.1},
{product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5},
{product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1}
]
},
xAxis: {
type: 'category', // 声明一个X轴,类目轴(category)。默认情况下,类目轴对应到 dataset 第一列
},
yAxis: {},
series: [ // 声明多个 bar 系列,默认情况下,每个系列会自动对应到 dataset 的每一列
{type: 'bar'},
{type: 'bar'},
{type: 'bar'},
]
};
myChart2.setOption(option2);
}
<div id="main" style="width: 600px;height: 400px;"></div>
<div id="main2" style="width: 600px;height: 400px;"></div>