uChart和ECharts虽然都能实现堆叠柱状图,但在实现方式和特性上有明显差异:
const option = {
series: [{
name: '系列1',
type: 'column',
stack: '总量',
data: [120, 132, 101, 134, 90, 230, 210]
}, {
name: '系列2',
type: 'column',
stack: '总量',
data: [220, 182, 191, 234, 290, 330, 310]
}],
yAxis: {
type: 'value'
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
}
};
const option = {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' }
},
legend: {
data: ['系列1', '系列2']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [
{
name: '系列1',
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '系列2',
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: [220, 182, 191, 234, 290, 330, 310]
}
]
};
配置项 | uChart | ECharts |
---|---|---|
堆叠标识 | stack: '总量' |
stack: 'total' |
系列类型 | type: 'column' |
type: 'bar' |
提示框配置 | 较简单 | 支持丰富的tooltip配置 |
动画效果 | 基础动画 | 支持多种动画效果 |
响应式设计 | 需手动处理 | 内置resize事件监听 |
选择uChart当:
选择ECharts当:
大数据量场景:
large
模式和progressiveChunkMode
移动端适配:
// 针对移动端触摸事件优化
myChart.on('touchstart', function(params) {
// 自定义处理逻辑
});
内存管理:
dispose()
释放资源clear()
而非重新创建实例希望这份对比能帮助您根据项目需求选择合适的图表库实现堆叠柱状图效果。