Skip to content

Commit f45eb97

Browse files
authored
Merge pull request #23 from aliyun/fix/docs
文档新增示例&data.color支持传入数组分别指定线和面积的颜色
2 parents 95432f7 + a9f59c8 commit f45eb97

File tree

8 files changed

+145
-8
lines changed

8 files changed

+145
-8
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Console Chart
22

3-
> Console Chart 是阿里云云管控解决方案开发套件的一部分。旨在为用户提供一款**开箱即用、统一视觉方案**的图表组件库。
3+
Console Chart 是阿里云云管控解决方案开发套件的一部分,旨在为用户提供一款**开箱即用、统一视觉方案**的图表组件库。
4+
5+
<p align="center">
6+
<a href=" https://www.alibabacloud.com"><img src="https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg"></a>
7+
</p>
8+
9+
[![NPM version][npm-image]][npm-url]
10+
11+
[npm-image]: https://img.shields.io/npm/v/@alicloud/console-chart.svg?style=flat-square
12+
[npm-url]: https://npmjs.org/package/@alicloud/console-chart
13+
414

515
## Install
616

packages/console-line-chart/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ import { ConsoleLineChart } from '@alicloud/console-chart';
3131

3232
[MDXInstruction:importDemo:XAxisTickInterval](./demo/XAxisTickInterval.tsx)
3333

34+
## 动态显示X轴
35+
36+
[MDXInstruction:importDemo:XAxisAsync](./demo/XAxisAsync.tsx)
37+
38+
## y轴最小值与正整数
39+
通过设置`yAxis.min`来设置坐标轴显示的最小值,通过`yAxis.formatter`来控制不显示浮点数。
40+
41+
[MDXInstruction:importDemo:YAxisMin](./demo/YAxisMin.tsx)
42+
3443
## 设置双轴
3544

3645
[MDXInstruction:importDemo:DoubleAxis](./demo/DoubleAxis.tsx)
@@ -51,6 +60,14 @@ import { ConsoleLineChart } from '@alicloud/console-chart';
5160

5261
[MDXInstruction:importDemo:Stack](./demo/Stack.tsx)
5362

63+
## 颜色渐变图
64+
65+
通过数据列里的`color`属性来进行指定,如果传入的值为字符串,则将该颜色应用到该数据列的`线图``面积图`上,也可以传入一个数组,第一个值指定`线图`的颜色,第二个值指定`面积图`的颜色
66+
67+
颜色色值支持传入渐变,渐变规则请看[G2渐变色原始文档](https://g2-v3.antv.vision/zh/docs/api/graphics#%E6%B8%90%E5%8F%98%E8%89%B2)
68+
69+
[MDXInstruction:importDemo:GradualColor](./demo/GradualColor.tsx)
70+
5471
# Config 配置
5572

5673
# 数据列配置
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { ConsoleLineChart } from '@alicloud/console-chart';
3+
4+
const data = [
5+
{
6+
name: 'A产品',
7+
data: [['2015', 20], ['2016', 5], ['2017', 15], ['2018', 30], ['2019', 40]],
8+
color: ['#0072ff', 'l (90) 0:#0072ff 1:#E3F2FD']
9+
},
10+
];
11+
12+
const config = {
13+
area: true,
14+
smooth: true,
15+
};
16+
17+
export default () => (
18+
<ConsoleLineChart data={data} config={config} height={300} />
19+
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { useState, Fragment } from 'react';
2+
import { ConsoleLineChart } from '@alicloud/console-chart';
3+
4+
const data = [
5+
{
6+
name: 'NAT',
7+
data: [
8+
[1522512000000, 302335],
9+
[1525104000000, 402335],
10+
[1527782400000, 202335],
11+
[1530374400000, 502335],
12+
[1533052800000, 102335],
13+
[1535731200000, 602335],
14+
[1538323200000, 202335],
15+
[1541001600000, 402335],
16+
],
17+
},
18+
];
19+
20+
const configDefault = {
21+
xAxis: {
22+
type: 'time',
23+
mask: 'YYYY-MM-DD'
24+
},
25+
};
26+
27+
const configInnner = {
28+
xAxis: {
29+
type: 'time',
30+
mask: 'YYYY-MM-DD HH:mm:ss'
31+
},
32+
}
33+
34+
export default () => {
35+
const [flag, setFlag] = useState(false);
36+
37+
const onClick = () => {
38+
setFlag(!flag);
39+
}
40+
41+
return (
42+
<Fragment>
43+
<button onClick={onClick}>点击事件</button>
44+
<ConsoleLineChart
45+
data={data}
46+
config={flag ? configDefault : configInnner}
47+
height={300}
48+
/>
49+
</Fragment>
50+
);
51+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { ConsoleLineChart } from '@alicloud/console-chart';
3+
4+
const data = [
5+
{
6+
name: 'A产品',
7+
data: [['2015', 4.3], ['2016', 3], ['2017', 2], ['2018', 0], ['2019', 1]],
8+
},
9+
];
10+
11+
const config = {
12+
yAxis: {
13+
min: 0,
14+
formatter: (num: number) => Math.round(num),
15+
}
16+
};
17+
18+
export default () => (
19+
<ConsoleLineChart data={data} config={config} height={300} />
20+
);

packages/console-line-chart/demo/index.stories.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ import Unit from './Unit';
1010
import Smooth from './Smooth';
1111
import Dot from './Dot';
1212
import Stack from './Stack';
13+
import XAxisAsync from './XAxisAsync';
14+
import YAxisMin from './YAxisMin';
15+
import GradualColor from './GradualColor';
1316

1417
storiesOf('ConsoleLineChart', module)
1518
.add('基本折线图', () => <Basic />)
1619
.add('多组数据', () => <Multi />)
1720
.add('自定义X轴label', () => <XLabel />)
1821
.add('自定义x轴时间刻度间距', () => <XAxisTickInterval />)
22+
.add('X轴动态变化', XAxisAsync)
23+
.add('Y轴最小值与正整数', YAxisMin)
1924
.add('设置双轴', () => <DoubleAxis />)
2025
.add('配置顶部单位', () => <Unit />)
2126
.add('设置光滑曲线', () => <Smooth />)
2227
.add('线条带点', () => <Dot />)
23-
.add('面积堆栈图', () => <Stack />);
28+
.add('面积堆栈图', () => <Stack />)
29+
.add('颜色渐变图', GradualColor)

packages/console-line-chart/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"checkJs": false,
2424
"resolveJsonModule": true,
2525
"noStrictGenericChecks": true,
26-
"noImplicitUseStrict": true
26+
"noImplicitUseStrict": true,
27+
"allowSyntheticDefaultImports": true
2728
},
2829
"exclude": ["node_modules"]
2930
}

packages/console-shared-utils/src/g2Helper/drawLine.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,50 @@ function drawLine(chart: any, config: any, yAxisKey = 'y') {
88
const lineShape = config.smooth ? 'smooth' : 'line';
99
const areaShape = config.smooth ? 'smooth' : 'area';
1010

11+
let clrsOne = [];
12+
let clrsTwo = [];
13+
(config.colors || []).forEach((x: string | [string, string]) => {
14+
if (Array.isArray(x)) {
15+
clrsOne.push(x[0]);
16+
clrsTwo.push(x[1]);
17+
} else if (typeof x === 'string') {
18+
clrsOne.push(x);
19+
clrsTwo.push(x);
20+
}
21+
});
22+
1123
if (config.area && config.stack) {
1224
chart
1325
.areaStack()
1426
.position(['x', yAxisKey])
15-
.color('type', config.colors)
27+
.color('type', clrsTwo)
1628
.shape(areaShape)
1729
.active(false);
1830
lineGeom = chart
1931
.lineStack()
2032
.position(['x', yAxisKey])
21-
.color('type', config.colors)
33+
.color('type', clrsOne)
2234
.shape(lineShape)
2335
.active(false);
2436
} else if (config.area && !config.stack) {
37+
console.log(config);
2538
chart
2639
.area()
2740
.position(['x', yAxisKey])
28-
.color('type', config.colors)
41+
.color('type', clrsTwo)
2942
.shape(areaShape)
3043
.active(false);
3144
lineGeom = chart
3245
.line()
3346
.position(['x', yAxisKey])
34-
.color('type', config.colors)
47+
.color('type', clrsOne)
3548
.shape(lineShape)
3649
.active(false);
3750
} else {
3851
lineGeom = chart
3952
.line()
4053
.position(['x', yAxisKey])
41-
.color('type', config.colors)
54+
.color('type', clrsOne)
4255
.shape(lineShape)
4356
.active(false);
4457
}

0 commit comments

Comments
 (0)