-
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.
docs: add radial graph demos (#6116)
* docs: add radial graph demos * docs: change radial demo screenshot url * docs: change radial stacked data transform
- Loading branch information
1 parent
e8192d2
commit 8444a63
Showing
4 changed files
with
213 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
site/examples/general/radial/demo/radial-bar-with-background.ts
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,65 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const data = [ | ||
{ type: '1-3秒', value: 0.16 }, | ||
{ type: '4-10秒', value: 0.125 }, | ||
{ type: '11-30秒', value: 0.2 }, | ||
{ type: '1-3分', value: 0.2 }, | ||
{ type: '3-10分', value: 0.05 }, | ||
{ type: '10-30分', value: 0.01 }, | ||
{ type: '30+分', value: 0.015 }, | ||
]; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
theme: 'dark', | ||
}); | ||
|
||
chart.data(data).coordinate({ type: 'radial', innerRadius: 0.35 }); | ||
|
||
chart | ||
.interval() | ||
.encode('x', 'type') | ||
.encode('y', 0.2) | ||
.style('fill', '#202020') | ||
.state({ | ||
active: { strokeWidth: 0 }, | ||
}) | ||
.tooltip(false); | ||
|
||
chart | ||
.interval() | ||
.encode('x', 'type') | ||
.encode('y', 'value') | ||
.encode('color', [ | ||
(val) => (val.type === '10-30分' || val.type === '30+分' ? 'high' : 'low'), | ||
]) | ||
.scale('color', { range: ['#5B8FF9', '#ff4d4f'] }) | ||
.style('radius', 20) | ||
.tooltip([ | ||
(item) => ({ | ||
name: item.type, | ||
value: item.value, | ||
}), | ||
]) | ||
.axis(false) | ||
.legend(false) | ||
.state({ | ||
active: { stroke: '#fff', strokeWidth: 1 }, | ||
}) | ||
.interaction('elementHighlight'); | ||
|
||
chart | ||
.image() | ||
.style('x', '50%') | ||
.style('y', '50%') | ||
.style('width', 100) | ||
.style('height', 80) | ||
.encode( | ||
'src', | ||
'https://gw.alipayobjects.com/mdn/rms_ef85c6/afts/img/A*0DYiQKP08cQAAAAAAAAAAAAAARQnAQ', | ||
) | ||
.tooltip(false); | ||
|
||
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,62 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const data = [ | ||
{ term: 'Zombieland', count: 9 }, | ||
{ term: 'Wieners', count: 8 }, | ||
{ term: 'Toy Story', count: 8 }, | ||
{ term: 'trashkannon', count: 7 }, | ||
{ term: 'the GROWLERS', count: 6 }, | ||
{ term: 'mudweiser', count: 6 }, | ||
{ term: 'ThunderCats', count: 4 }, | ||
{ term: 'The Taqwacores - Motion Picture', count: 4 }, | ||
{ term: 'The Shawshank Redemption', count: 2 }, | ||
{ term: 'The Olivia Experiment', count: 1 }, | ||
]; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
padding: 50, | ||
}); | ||
|
||
chart | ||
.data(data) | ||
.coordinate({ type: 'radial', innerRadius: 0.2, endAngle: Math.PI }); | ||
|
||
chart | ||
.interval() | ||
.encode('x', 'term') | ||
.encode('y', 'count') | ||
.encode('size', 5) | ||
.axis({ | ||
y: false, | ||
x: { | ||
title: false, | ||
}, | ||
}); | ||
|
||
chart | ||
.point() | ||
.encode('x', 'term') | ||
.encode('y', 'count') | ||
.encode('shape', 'point') | ||
.encode('size', 4) | ||
.tooltip({ | ||
title: (item) => item.term, | ||
items: [ | ||
(item) => ({ | ||
name: 'count', | ||
value: item.count, | ||
}), | ||
], | ||
}); | ||
|
||
chart | ||
.text() | ||
.style('text', 'Music') | ||
.style('x', '50%') | ||
.style('y', '50%') | ||
.style('textAlign', 'center') | ||
.style('fontSize', 24); | ||
|
||
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,62 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const data = [ | ||
{ State: 'WY', 小于5岁: 25635, '5至13岁': 1890, '14至17岁': 9314 }, | ||
{ State: 'DC', 小于5岁: 30352, '5至13岁': 20439, '14至17岁': 10225 }, | ||
{ State: 'VT', 小于5岁: 38253, '5至13岁': 42538, '14至17岁': 15757 }, | ||
{ State: 'ND', 小于5岁: 51896, '5至13岁': 67358, '14至17岁': 18794 }, | ||
{ State: 'AK', 小于5岁: 72083, '5至13岁': 85640, '14至17岁': 22153 }, | ||
]; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
}); | ||
|
||
chart.coordinate({ type: 'radial' }); | ||
|
||
chart | ||
.interval() | ||
.data({ | ||
value: data, | ||
transform: [ | ||
{ | ||
type: 'fold', | ||
fields: ['小于5岁', '5至13岁', '14至17岁'], | ||
key: '年龄段', | ||
value: '人口数量', | ||
retains: ['State'], | ||
}, | ||
], | ||
}) | ||
.encode('x', 'State') | ||
.encode('y', '人口数量') | ||
.encode('color', '年龄段') | ||
.scale('y', { domainMax: 200000 }) | ||
.scale('color', { range: ['#6395FA', '#62DAAB', '#657798'] }) | ||
.transform({ type: 'stackY' }) | ||
.axis({ | ||
x: { | ||
title: false, | ||
line: true, | ||
}, | ||
y: { | ||
line: true, | ||
grid: true, | ||
gridLineDash: [4, 4], | ||
tickCount: 10, | ||
tickFilter: (datum) => datum != 200000, | ||
}, | ||
}) | ||
.legend({ | ||
color: { | ||
position: 'bottom', | ||
layout: { justifyContent: 'center' }, | ||
}, | ||
}) | ||
.interaction('elementHighlightByX') | ||
.interaction('tooltip', { | ||
shared: true, | ||
}); | ||
|
||
chart.render(); |