Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions site/docs/api/chart/axis.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ const data = [

输出数据的范围,数值类型的默认值为 [0, 1],格式为 [min, max],min 和 max 均为 0 至 1

### labelAutoHide: boolean

自动隐藏重叠的刻度值,保证均匀步长、且保留第一个和最后一个 tick 的前提下,若遮挡则进行隐藏,兜底展示不均匀步长。默认为 `false`

### labelAutoRotate: boolean

自动旋转刻度值,若坐标轴文本遮挡则进行最小角度旋转。默认为 `false`

### formatter: Function

回调函数,用于格式化坐标轴刻度点的文本显示,会影响数据在坐标轴 axis、图例 legend、提示信息 tooltip 上的显示。
Expand Down
22 changes: 22 additions & 0 deletions site/examples/component/axis/demo/labelAutoHide.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @jsx jsx */
import { Axis, Canvas, Chart, Interval, jsx } from '@antv/f2';

const context = document.getElementById('container').getContext('2d');

const data = Array.from({ length: 100 }, (_, i) => ({
category: `Cat${i + 1}`,
value: ((i % 10) + 1) * 10,
}));

const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="category" labelAutoHide={true} />
<Axis field="value" />
<Interval x="category" y="value" color="#722ED1" />
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
canvas.render();
35 changes: 35 additions & 0 deletions site/examples/component/axis/demo/labelAutoRotate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @jsx jsx */
import { Axis, Canvas, Chart, Interval, jsx } from '@antv/f2';

const context = document.getElementById('container').getContext('2d');

const data = [
{ category: 'Category1', value: 10 },
{ category: 'Category2', value: 15 },
{ category: 'Category3', value: 20 },
{ category: 'Category4', value: 25 },
{ category: 'Category5', value: 30 },
{ category: 'Category6', value: 35 },
{ category: 'Category7', value: 40 },
{ category: 'Category8', value: 45 },
{ category: 'Category9', value: 50 },
{ category: 'Category10', value: 55 },
{ category: 'Category11', value: 60 },
{ category: 'Category12', value: 65 },
{ category: 'Category13', value: 70 },
{ category: 'Category14', value: 75 },
{ category: 'Category15', value: 80 },
];

const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="category" labelAutoRotate={true} />
<Axis field="value" />
<Interval x="category" y="value" color="#2FC25B" />
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
canvas.render();
18 changes: 18 additions & 0 deletions site/examples/component/axis/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"title": {
"zh": "中文分类",
"en": "Category"
},
"demos": [
{
"filename": "labelAutoHide.jsx",
"title": "文本标注",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当前标题 “文本标注” 描述不够具体。为了更清晰地说明该示例的功能,建议修改为 “自动隐藏标签”,这与 index.zh.md 中的章节标题也能保持一致。

Suggested change
"title": "文本标注",
"title": "自动隐藏标签",

"screenshot": "https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/c95b75fc-d81e-4ae2-8cbf-29f4ba7bf706.png"
},
{
"filename": "labelAutoRotate.jsx",
"title": "点标注",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当前标题 “点标注” 似乎与示例内容不符。该示例演示的是标签自动旋转功能。建议修改为 “自动旋转标签”,这与 index.zh.md 中的章节标题也能保持一致。

Suggested change
"title": "点标注",
"title": "自动旋转标签",

"screenshot": "https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/eecfc128-cb32-4797-b41c-697823ff2336.png"
}
]
}
4 changes: 4 additions & 0 deletions site/examples/component/axis/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Axis
order: 3
---
77 changes: 77 additions & 0 deletions site/examples/component/axis/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: 坐标轴 Axis
order: 3
---

坐标轴(Axis)是图表中用于展示数据范围和刻度的组件,帮助用户理解数据的分布和趋势。F2 提供了灵活的坐标轴配置,支持自动旋转、自动隐藏、自定义样式等功能。

## 代码演示

### 自动旋转标签

当坐标轴标签过长或数量过多时,可以启用自动旋转功能,避免标签重叠。

```jsx
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

此处的示例代码缺少 context 的定义,如果用户直接复制运行会报错。建议在 import 语句后补充 context 的获取逻辑,以确保示例代码的完整性和可运行性。

Suggested change
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';
const context = document.getElementById('container').getContext('2d');


const data = [
{ category: 'Category1', value: 10 },
{ category: 'Category2', value: 15 },
{ category: 'Category3', value: 20 },
{ category: 'Category4', value: 25 },
{ category: 'Category5', value: 30 },
{ category: 'Category6', value: 35 },
{ category: 'Category7', value: 40 },
{ category: 'Category8', value: 45 },
{ category: 'Category9', value: 50 },
{ category: 'Category10', value: 55 },
{ category: 'Category11', value: 60 },
{ category: 'Category12', value: 65 },
{ category: 'Category13', value: 70 },
{ category: 'Category14', value: 75 },
{ category: 'Category15', value: 80 },
];

const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="category" labelAutoRotate={true} />
<Axis field="value" />
<Interval x="category" y="value" color="#2FC25B" />
</Chart>
</Canvas>
);
```

### 自动隐藏标签

当标签过多时,可以启用自动隐藏功能,自动隐藏部分标签以避免重叠。

```jsx
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

此处的示例代码缺少 context 的定义,如果用户直接复制运行会报错。建议在 import 语句后补充 context 的获取逻辑,以确保示例代码的完整性和可运行性。

Suggested change
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';
import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2';
const context = document.getElementById('container').getContext('2d');


const data = Array.from({ length: 100 }, (_, i) => ({
category: `Cat${i + 1}`,
value: ((i % 10) + 1) * 10,
}));

const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="category" labelAutoHide={true} />
<Axis field="value" />
<Interval x="category" y="value" color="#722ED1" />
</Chart>
</Canvas>
);
```

## API

| 属性名 | 类型 | 默认值 | 说明 |
| --------------- | ------- | ------ | ------------------------------------ |
| field | string | - | 绑定的数据字段名 |
| labelAutoRotate | boolean | false | 是否启用标签自动旋转 |
| labelAutoHide | boolean | false | 是否启用标签自动隐藏 |
| safetyDistance | number | 0 | 标签之间的安全距离,用于自动旋转计算 |
| style | object | - | 自定义样式配置 |
Loading