@@ -3,6 +3,83 @@ title: 层叠面积图
33order : 1
44---
55
6- - [ 百分比分组柱图] ( ./demo/percent.jsx )
7- - [ 区域图(存在空值)] ( ./demo/area-none.jsx )
8- - [ 层叠面积图] ( ./demo/stacked.jsx )
6+ 层叠面积图是一种特殊的面积图,它可以展示多个数据系列随时间或其他连续变量变化的累积效果。通过堆叠的方式,可以直观地表现出各个类别的数据在整体中的占比及其变化趋势。
7+
8+ ## 代码演示
9+
10+ ### 基础示例
11+
12+ - [ 层叠面积图] ( ./demo/stacked.jsx ) :展示多个数据系列的累积变化趋势。
13+
14+ ``` jsx
15+ import { jsx , Canvas , Chart , Area , Line , Axis , Legend } from ' @antv/f2' ;
16+
17+ const { props } = (
18+ < Canvas context= {context}>
19+ < Chart
20+ data= {data}
21+ scale= {{
22+ date: {
23+ range: [0 , 1 ],
24+ },
25+ value: {
26+ min: 0 ,
27+ nice: true ,
28+ },
29+ }}
30+ >
31+ < Axis field= " date" / >
32+ < Axis field= " value" / >
33+ < Area x= " date" y= " value" color= " city" adjust= " stack" / >
34+ < Line x= " date" y= " value" color= " city" adjust= " stack" / >
35+ < Legend style= {{ justifyContent: ' space-around' }} / >
36+ < / Chart>
37+ < / Canvas>
38+ );
39+ ```
40+
41+ ### 进阶用法
42+
43+ - [ 百分比层叠面积图] ( ./demo/percent.jsx ) :以百分比的形式展示各个类别在总体中的占比变化。
44+
45+ ``` jsx
46+ import { jsx , Canvas , Chart , Area , Line , Axis , Legend } from ' @antv/f2' ;
47+
48+ function formatterPercent (value ) {
49+ value = value || 0 ;
50+ return parseInt (value * 100 ) + ' %' ;
51+ }
52+
53+ const { props } = (
54+ < Canvas context= {context}>
55+ < Chart
56+ data= {data}
57+ scale= {{
58+ year: {
59+ range: [0 , 1 ],
60+ },
61+ percent: {
62+ formatter: formatterPercent,
63+ alias: ' percent(%)' ,
64+ },
65+ }}
66+ >
67+ < Axis field= " percent" / >
68+ < Axis field= " year" / >
69+ < Area x= " year" y= " percent" color= " country" adjust= " stack" / >
70+ < Line x= " year" y= " percent" color= " country" adjust= " stack" / >
71+ < Legend style= {{ justifyContent: ' space-around' }} / >
72+ < / Chart>
73+ < / Canvas>
74+ );
75+ ```
76+
77+ - [ 区域图(存在空值)] ( ./demo/area-none.jsx ) :演示如何处理数据中存在空值的情况。
78+
79+ ## 使用场景
80+
81+ 层叠面积图适用于以下场景:
82+
83+ 1 . 展示多个相关数据系列随时间的变化趋势
84+ 2 . 分析各个类别对总体的贡献度
85+ 3 . 比较不同类别数据的占比变化
0 commit comments