uChart和ECharts虽然都能实现堆叠柱状图效果,但两者在实现方式和功能特性上有明显差异:
option = {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' }
},
legend: {
data: ['系列1', '系列2', '系列3']
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [
{
name: '系列1',
type: 'bar',
stack: 'total', // 关键堆叠配置
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '系列2',
type: 'bar',
stack: 'total', // 相同stack值实现堆叠
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '系列3',
type: 'bar',
stack: 'total', // 相同stack值实现堆叠
data: [150, 232, 201, 154, 190, 330, 410]
}
]
};
const option = {
series: [
{
name: '系列1',
type: 'bar',
stack: true, // 开启堆叠
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '系列2',
type: 'bar',
stack: true, // 开启堆叠
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '系列3',
type: 'bar',
stack: true, // 开启堆叠
data: [150, 232, 201, 154, 190, 330, 410]
}
],
categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
};
stack: 'groupName'
stack: true
responsive: true
和媒体查询选择ECharts当需要:
选择uChart当需要:
对于移动端,无论选择哪个库,都建议:
1. 合理设置动画选项
2. 避免过多数据点(移动端建议不超过50个数据点)
3. 对于uChart,可以利用其内置的按需渲染特性
4. 对于ECharts,使用large: true
选项处理大数据量