-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legend): 图例支持回调设置 marker (#3448)
* feat(legend): 图例支持回调设置 marker * docs(legend): 添加图例 marker 设置文档
- Loading branch information
Showing
11 changed files
with
263 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`markdown:docs/common/api..md` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`markdown:docs/common/api.zh.md` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const data = [ | ||
{ name: 'London', 月份: 'Jan.', 月均降雨量: 18.9 }, | ||
{ name: 'London', 月份: 'Feb.', 月均降雨量: 28.8 }, | ||
{ name: 'London', 月份: 'Mar.', 月均降雨量: 39.3 }, | ||
{ name: 'London', 月份: 'Apr.', 月均降雨量: 81.4 }, | ||
{ name: 'London', 月份: 'May', 月均降雨量: 47 }, | ||
{ name: 'London', 月份: 'Jun.', 月均降雨量: 20.3 }, | ||
{ name: 'London', 月份: 'Jul.', 月均降雨量: 24 }, | ||
{ name: 'London', 月份: 'Aug.', 月均降雨量: 35.6 }, | ||
{ name: 'Berlin', 月份: 'Jan.', 月均降雨量: 12.4 }, | ||
{ name: 'Berlin', 月份: 'Feb.', 月均降雨量: 23.2 }, | ||
{ name: 'Berlin', 月份: 'Mar.', 月均降雨量: 34.5 }, | ||
{ name: 'Berlin', 月份: 'Apr.', 月均降雨量: 99.7 }, | ||
{ name: 'Berlin', 月份: 'May', 月均降雨量: 52.6 }, | ||
{ name: 'Berlin', 月份: 'Jun.', 月均降雨量: 35.5 }, | ||
{ name: 'Berlin', 月份: 'Jul.', 月均降雨量: 37.4 }, | ||
{ name: 'Berlin', 月份: 'Aug.', 月均降雨量: 42.4 }, | ||
]; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
height: 500, | ||
}); | ||
|
||
chart.data(data); | ||
chart.scale('月均降雨量', { | ||
nice: true, | ||
}); | ||
chart.tooltip({ | ||
shared: true, | ||
showMarkers: false, | ||
}); | ||
chart.legend({ | ||
custom: true, | ||
items: [ | ||
{ | ||
name: '城市 1', | ||
id: 'city-1', | ||
marker: { symbol: 'triangle', style: { r: 4, fill: 'red' } }, | ||
}, | ||
{ | ||
name: '城市 2', | ||
id: 'city-2', | ||
}, | ||
], | ||
}); | ||
|
||
chart.interval().position('月份*月均降雨量').color('name').adjust('stack'); | ||
|
||
chart.interaction('active-region'); | ||
|
||
chart.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const data = [ | ||
{ name: 'London', 月份: 'Jan.', 月均降雨量: 18.9 }, | ||
{ name: 'London', 月份: 'Feb.', 月均降雨量: 28.8 }, | ||
{ name: 'London', 月份: 'Mar.', 月均降雨量: 39.3 }, | ||
{ name: 'London', 月份: 'Apr.', 月均降雨量: 81.4 }, | ||
{ name: 'London', 月份: 'May', 月均降雨量: 47 }, | ||
{ name: 'London', 月份: 'Jun.', 月均降雨量: 20.3 }, | ||
{ name: 'London', 月份: 'Jul.', 月均降雨量: 24 }, | ||
{ name: 'London', 月份: 'Aug.', 月均降雨量: 35.6 }, | ||
{ name: 'Berlin', 月份: 'Jan.', 月均降雨量: 12.4 }, | ||
{ name: 'Berlin', 月份: 'Feb.', 月均降雨量: 23.2 }, | ||
{ name: 'Berlin', 月份: 'Mar.', 月均降雨量: 34.5 }, | ||
{ name: 'Berlin', 月份: 'Apr.', 月均降雨量: 99.7 }, | ||
{ name: 'Berlin', 月份: 'May', 月均降雨量: 52.6 }, | ||
{ name: 'Berlin', 月份: 'Jun.', 月均降雨量: 35.5 }, | ||
{ name: 'Berlin', 月份: 'Jul.', 月均降雨量: 37.4 }, | ||
{ name: 'Berlin', 月份: 'Aug.', 月均降雨量: 42.4 }, | ||
]; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
height: 500, | ||
}); | ||
|
||
chart.data(data); | ||
chart.scale('月均降雨量', { | ||
nice: true, | ||
}); | ||
chart.tooltip({ | ||
shared: true, | ||
showMarkers: false, | ||
}); | ||
chart.legend({ | ||
marker: (name, index, item) => { | ||
return { | ||
symbol: index === 0 ? 'circle' : 'diamond', | ||
style: { | ||
fill: index === 0 ? 'purple' : 'green', | ||
stroke: '#363636', | ||
lineWidth: 1, | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
chart.interval().position('月份*月均降雨量').color('name').adjust('stack'); | ||
chart.interaction('active-region'); | ||
|
||
chart.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "marker-callback.ts", | ||
"title": { | ||
"zh": "通过回调设置 legend marker", | ||
"en": "Legend marker with callback" | ||
}, | ||
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/XYbSi6Ztbo/f5bd6aff-61fa-41ff-ab3b-8de9be14d053.png" | ||
}, | ||
{ | ||
"filename": "custom-items.ts", | ||
"title": { | ||
"zh": "自定义图例 items", | ||
"en": "Custom legend items" | ||
}, | ||
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/PgYlI9hB3Z/c50fffd5-5db0-49f2-ba16-ee3f523905bc.png" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Legend | ||
order: 4 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: 图例 | ||
order: 4 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters