Skip to content

Commit 508513e

Browse files
i11I04ilkd01632719
and
lkd01632719
authored
docs: add demo (#2367)
Co-authored-by: lkd01632719 <[email protected]>
1 parent 58c8f5a commit 508513e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

site/examples/statistics/line/demo/meta.json

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575
"en": "Slider"
7676
},
7777
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*xZAVSKcWzrwAAAAAAAAAAAAADmJ7AQ/original"
78+
},
79+
{
80+
"filename": "style-callback.js",
81+
"title": {
82+
"zh": "通过回调函数指定折线样式",
83+
"en": "Set line style through callback"
84+
},
85+
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*p1n4RI9YynkAAAAAAAAAAAAADmJ7AQ/original"
7886
}
7987
]
8088
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Line } from '@ant-design/plots';
2+
import React, { useState, useEffect } from 'react';
3+
import ReactDOM from 'react-dom';
4+
5+
const DemoLine = () => {
6+
const [data, setData] = useState([]);
7+
8+
useEffect(() => {
9+
asyncFetch();
10+
}, []);
11+
12+
const asyncFetch = () => {
13+
fetch('https://gw.alipayobjects.com/os/bmw-prod/c48dbbb1-fccf-4a46-b68f-a3ddb4908b68.json')
14+
.then((response) => response.json())
15+
.then((json) => setData(json))
16+
.catch((error) => {
17+
console.log('fetch data failed', error);
18+
});
19+
};
20+
const config = {
21+
data,
22+
xField: 'date',
23+
yField: 'value',
24+
colorField: 'type',
25+
axis: {
26+
y: {
27+
labelFormatter: (v) => `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, (s) => `${s},`),
28+
},
29+
},
30+
scale: { color: { range: ['#30BF78', '#F4664A', '#FAAD14'] } },
31+
style: {
32+
lineWidth: 2,
33+
lineDash: (data) => {
34+
if (data[0].type === 'register') return [4, 4];
35+
},
36+
opacity: (data) => {
37+
if (data[0].type !== 'register') return 0.5;
38+
},
39+
},
40+
};
41+
42+
return <Line {...config} />;
43+
};
44+
45+
ReactDOM.render(<DemoLine />, document.getElementById('container'));

0 commit comments

Comments
 (0)