Appearance
你正在查看 v1.0.1 文档。切换到最新版请访问:/
平滑折线
功能说明(What)
平滑折线用于弱化折点,让趋势线更柔和,常用于观感优化与趋势展示。
应用场景(When)
- 需要视觉更柔和的趋势展示
- 点位噪声较多的数据
快速上手(How - Quick)
ts
import { BaseLine } from '@ymhc/harmonycharts';
import type { BaseLineConfig } from '@ymhc/harmonycharts';
@Entry
struct Index {
@Prop baseLineConfig: BaseLineConfig = {
categories: ['Mon', 'Tue', 'Wed', 'Thu'],
series: [{ name: 'Trend', data: [120, 200, 150, 80], smooth: true }],
tooltip: { show: true, trigger: 'axis', confine: true },
legend: { show: true }
};
build() {
Column() {
BaseLine({ config: this.baseLineConfig, chartHeight: 220 })
}
}
}运行结果
完整示例配置(整页可用)
ts
const option: HarmonyChartsOption = {
grid: { top: 28, left: 12, right: 12, bottom: 24 },
tooltip: { show: true, trigger: 'axis', triggerOn: 'mousemove', confine: true },
legend: { show: true },
xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu'], boundaryGap: false },
yAxis: { type: 'value', includeZero: true },
series: [
{ type: 'line', name: 'Trend', data: [120, 200, 150, 80], smooth: true, lineStyle: { color: '#5470C6', width: 2 } }
]
};默认值(精确工程默认)
该页面默认值与 BaseLine 一致,详见总览页「默认值(精确工程默认)」。
配置项说明(API)
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| smooth | 是否平滑 | boolean | number | false |
| lineStyle | 线条样式 | LineStrokeStyle | - |
事件与交互(Events)
ts
chart.on('click', (params) => {
// params.seriesType === 'line'
});高级用法(Advanced)
- 平滑曲线 + dataZoom 交互
注意事项 / 设计说明(Notes)
- smooth 为 number 时表示曲率强度。