uChart和ECharts虽然都能实现堆叠柱状图,但它们在API设计、配置方式和性能优化上有明显差异:
option = {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' }
},
legend: {
data: ['系列1', '系列2', '系列3']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [
{
name: '系列1',
type: 'bar',
stack: '总量',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '系列2',
type: 'bar',
stack: '总量',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '系列3',
type: 'bar',
stack: '总量',
data: [150, 232, 201, 154, 190, 330, 410]
}
]
};
const option = {
series: [
{
name: '系列1',
type: 'bar',
stack: '总量',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '系列2',
type: 'bar',
stack: '总量',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '系列3',
type: 'bar',
stack: '总量',
data: [150, 232, 201, 154, 190, 330, 410]
}
],
categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
yAxis: {
format: val => val // 数值格式化
},
legend: {
show: true
},
tooltip: {
show: true
}
};
配置结构:
性能优化:
交互功能:
选择ECharts如果:
选择uChart如果:
两者都能实现优秀的堆叠柱状图效果,选择应基于项目具体需求和运行环境考虑。