Skip to content

Commit

Permalink
docs: 增加 column,bar 背景色设置的demo & 图表指引 (#2333)
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky authored Feb 19, 2021
1 parent 2f0961b commit 967c1e6
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 119 deletions.
1 change: 0 additions & 1 deletion docs/common/bar-style.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

`markdown:docs/common/shape-style.zh.md`


#### barBackground.style

<description>**可选** _StyleAttr_</description>
Expand Down
1 change: 0 additions & 1 deletion docs/common/column-style.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

`markdown:docs/common/shape-style.zh.md`


#### columnBackground.style

<description>**可选** _StyleAttr_</description>
Expand Down
16 changes: 15 additions & 1 deletion docs/manual/plots/bar.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,25 @@ bar.render();

## Bar plot features

### Set corner-radius of column
### Specify minWidth and maxWidth of bar

Using `maxBarWidth` to specify the maximum width of bar, and `minBarWidth` to specify the minimum width of bar.

通过组合指定柱子最大宽度、最小宽度可以达到指定柱子宽度的效果。

<playground path="bar/basic/demo/width.ts" rid="specify-bar-width"></playground>

### Set corner-radius of bar

通过设置 `barStyle.radius` 可以指定柱子的圆角,数据类型可以是 `number` 也可以是 `number[]`

当柱子数值为正值时,`const [r1, r2, r3, r4] = radius` 依次代表柱子左上角、右上角、右下角、左下角的 `radius`
当柱子数值为负值时,`const [r1, r2, r3, r4] = radius` 依次代表柱子左下角、右下角、右上角、左上角的 `radius`

<playground path="bar/grouped/demo/corner-radius.ts" rid="corner-radius"></playground>

### Set background style of bar

Using `barBackground.style` to specify the background style of bar.

<playground path="bar/basic/demo/bar-background.ts" rid="bar-background"></playground>
14 changes: 14 additions & 0 deletions docs/manual/plots/bar.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ bar.render();

## 条形图特性

### 指定柱子最大宽度、最小宽度

通过设置 `maxBarWidth` 可以指定柱子的最大宽度,设置 `minBarWidth` 可以指定柱子的最小宽度。

通过组合指定柱子最大宽度、最小宽度可以达到指定柱子宽度的效果。

<playground path="bar/basic/demo/width.ts" rid="specify-bar-width"></playground>

### 设置柱子的圆角

通过设置 `barStyle.radius` 可以指定柱子的圆角,数据类型可以是 `number` 也可以是 `number[]`
Expand All @@ -129,3 +137,9 @@ bar.render();
当柱子数值为负值时,`const [r1, r2, r3, r4] = radius` 依次代表柱子左下角、右下角、右上角、左上角的 `radius`

<playground path="bar/grouped/demo/corner-radius.ts" rid="corner-radius"></playground>

### 设置柱子的背景样式

通过设置 `barBackground.style` 可以指定柱子的背景样式。

<playground path="bar/basic/demo/bar-background.ts" rid="bar-background"></playground>
10 changes: 8 additions & 2 deletions docs/manual/plots/column.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ fetch('https://gw.alipayobjects.com/os/antfincdn/K0kfOzo4j%24/column.json')

<playground path="column/grouped/demo/basic.ts" rid="group-column"></playground>

### Specify minWidth and maxColumnWidth of column
### Specify minWidth and maxWidth of column

通过设置 `maxColumnWidth` 可以指定柱子的最大宽度,设置 `minColumnWidth` 可以指定柱子的最小宽度。
Using `maxColumnWidth` to specify the maximum width of column, and `minColumnWidth` to specify the minimum width of column.

通过组合指定柱子最大宽度、最小宽度可以达到指定柱子宽度的效果。

Expand All @@ -148,3 +148,9 @@ fetch('https://gw.alipayobjects.com/os/antfincdn/K0kfOzo4j%24/column.json')
当柱子数值为负值时,`const [r1, r2, r3, r4] = radius` 依次代表柱子左下角、右下角、右上角、左上角的 `radius`

<playground path="column/grouped/demo/corner-radius.ts" rid="corner-radius"></playground>

### Set background style of column

Using `columnBackground.style` to specify the background style of column.

<playground path="column/stacked/demo/column-background.ts" rid="column-background"></playground>
5 changes: 5 additions & 0 deletions docs/manual/plots/column.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@ fetch('https://gw.alipayobjects.com/os/antfincdn/K0kfOzo4j%24/column.json')

<playground path="column/grouped/demo/corner-radius.ts" rid="corner-radius"></playground>

### 设置柱子的背景样式

通过设置 `columnBackground.style` 可以指定柱子的背景样式。

<playground path="column/stacked/demo/column-background.ts" rid="column-background"></playground>
29 changes: 29 additions & 0 deletions examples/bar/basic/demo/bar-background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Bar } from '@antv/g2plot';

const data = [
{ type: '家具家电', sales: 38 },
{ type: '粮油副食', sales: 52 },
{ type: '生鲜水果', sales: 61 },
{ type: '美容洗护', sales: 145 },
{ type: '母婴用品', sales: 48 },
{ type: '进口食品', sales: 38 },
{ type: '食品饮料', sales: 38 },
{ type: '家庭清洁', sales: 38 },
];

const bar = new Bar('container', {
data,
xField: 'sales',
yField: 'type',
legend: {
position: 'top-left',
},
barBackground: {
style: {
fill: 'rgba(0,0,0,0.1)',
},
},
interactions: [{ type: 'active-region', enable: false }],
});

bar.render();
8 changes: 8 additions & 0 deletions examples/bar/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
"en": "Bar plot conversion tag"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/KhabP6L2tr/cf602236-7932-4ef7-b3d6-d98a219c798e.png"
},
{
"filename": "bar-background.ts",
"title": {
"zh": "设置条形图背景色",
"en": "Bar plot with backgorund"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/t6ut5YQMPB/bar-background.png"
}
]
}
139 changes: 25 additions & 114 deletions examples/column/stacked/demo/basic.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,28 @@
import { Column } from '@antv/g2plot';

const data = [
{
year: '1991',
value: 3,
type: 'Lon',
},
{
year: '1992',
value: 4,
type: 'Lon',
},
{
year: '1993',
value: 3.5,
type: 'Lon',
},
{
year: '1994',
value: 5,
type: 'Lon',
},
{
year: '1995',
value: 4.9,
type: 'Lon',
},
{
year: '1996',
value: 6,
type: 'Lon',
},
{
year: '1997',
value: 7,
type: 'Lon',
},
{
year: '1998',
value: 9,
type: 'Lon',
},
{
year: '1999',
value: 13,
type: 'Lon',
},
{
year: '1991',
value: 3,
type: 'Bor',
},
{
year: '1992',
value: 4,
type: 'Bor',
},
{
year: '1993',
value: 3.5,
type: 'Bor',
},
{
year: '1994',
value: 5,
type: 'Bor',
},
{
year: '1995',
value: 4.9,
type: 'Bor',
},
{
year: '1996',
value: 6,
type: 'Bor',
},
{
year: '1997',
value: 7,
type: 'Bor',
},
{
year: '1998',
value: 9,
type: 'Bor',
},
{
year: '1999',
value: 13,
type: 'Bor',
},
];
fetch('https://gw.alipayobjects.com/os/antfincdn/8elHX%26irfq/stack-column-data.json')
.then((data) => data.json())
.then((data) => {
const stackedColumnPlot = new Column('container', {
data,
isStack: true,
xField: 'year',
yField: 'value',
seriesField: 'type',
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'top', 'bottom', 'middle'
// 可配置附加的布局方法
layout: [
// 柱形图数据标签位置自动调整
{ type: 'interval-adjust-position' },
// 数据标签防遮挡
{ type: 'interval-hide-overlap' },
// 数据标签文颜色自动调整
{ type: 'adjust-color' },
],
},
});

const stackedColumnPlot = new Column('container', {
data,
isStack: true,
xField: 'year',
yField: 'value',
seriesField: 'type',
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'top', 'bottom', 'middle'
// 可配置附加的布局方法
layout: [
// 柱形图数据标签位置自动调整
{ type: 'interval-adjust-position' },
// 数据标签防遮挡
{ type: 'interval-hide-overlap' },
// 数据标签文颜色自动调整
{ type: 'adjust-color' },
],
},
});

stackedColumnPlot.render();
stackedColumnPlot.render();
});
25 changes: 25 additions & 0 deletions examples/column/stacked/demo/column-background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Column } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/antfincdn/8elHX%26irfq/stack-column-data.json')
.then((data) => data.json())
.then((data) => {
const stackedColumnPlot = new Column('container', {
data,
isStack: true,
xField: 'year',
yField: 'value',
seriesField: 'type',
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'top', 'bottom', 'middle'
},
interactions: [{ type: 'active-region', enable: false }],
columnBackground: {
style: {
fill: 'rgba(0,0,0,0.1)',
},
},
});

stackedColumnPlot.render();
});
8 changes: 8 additions & 0 deletions examples/column/stacked/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
"en": "Stacked column plot"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/KLJB0t7S9W/93ca0482-9d1d-42e9-b99c-c70d87517888.png"
},
{
"filename": "column-background",
"title": {
"zh": "设置柱状图背景色",
"en": "Column plot with background"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/pgOqla53EK/column-background.png"
}
]
}

0 comments on commit 967c1e6

Please sign in to comment.