Appearance
分组柱状图(并列对比)
功能说明(What)
分组柱状图用于展示多系列并列对比,适合同一类目下的多指标比较。
应用场景(When)
- 多指标并列对比
- 同类目多系列比较
快速上手(How - Quick)
ts
import { BaseBar } from '@ymhc/harmonycharts'; // 引入基础柱状图组件
import type { BaseBarConfig } from '@ymhc/harmonycharts'; // 引入柱状图配置类型
@Entry // 入口页面
struct Index { // 页面结构体
@Prop baseBarConfig: BaseBarConfig = { // 组件配置(可响应)
categories: ['Mon', 'Tue', 'Wed'], // X 轴类目
series: [ // 多系列并列
{ name: 'Sales', data: [120, 200, 150] }, // 系列 A
{ name: 'Profit', data: [60, 140, 100] } // 系列 B
],
grid: { top: 24, left: 16, right: 16, bottom: 28 }, // 画布边距
tooltip: { show: true, trigger: 'axis', confine: true }, // 轴触发提示
legend: { show: true } // 图例开关
}; // 配置结束
build() { // 页面构建
Column() { // 纵向布局
BaseBar({ config: this.baseBarConfig, chartHeight: 220 }) // 渲染柱状图
} // 布局结束
} // 构建结束
}完整示例配置(整页可用)
ts
const option: HarmonyChartsOption = {
grid: { top: 24, left: 16, right: 16, bottom: 28 },
tooltip: { show: true, trigger: 'axis', confine: true },
legend: { show: true },
xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed'] },
yAxis: { type: 'value', includeZero: true },
series: [
{ type: 'bar', name: 'Sales', data: [120, 200, 150] },
{ type: 'bar', name: 'Profit', data: [60, 140, 100] }
]
};示例图
配置项说明(API)
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| barGap | 柱间距 | number | 未设置 |
| barCategoryGap | 类目间距 | number | 未设置 |
事件与交互(Events)
ts
chart.on('click', (params) => {
// params.seriesType === 'bar'
});高级用法(Advanced)
- 系列较多时建议开启 legend 过滤
注意事项 / 设计说明(Notes)
- 分组较多时注意 label 重叠。