使用dataset数据集实现:
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
"type": "category",
},
yAxis:{
"type": "value",
},
dataset: {
source: [
['product', '2015', '2016', '2017'],
['Apples', 50, 80, 120],
['Oranges', 70, 100, 140],
['Bananas', 40, 60, 90],
],
// 用 dimensions 指定了维度的顺序。直角坐标系中,如果 x轴 type 为 category
// 默认把第一个维度映射到 X 轴上(第一列),后面维度映射到 Y 轴上。
dimensions: [
'product',//
'2015',
'2016',
'2017'
],
series: [
{
"type": "bar",
// 给一个系列的 stack 值设置一个字符串类型的值
// 拥有同样 stack 值的系列将堆叠在一组
"stack": "fruit",
},
{
"type": "bar",
"stack": "fruit",
},
{
"type": "bar",
"stack": "fruit",
}
]
};