Skip to content

Commit

Permalink
docs: example for pie with center text (#5714)
Browse files Browse the repository at this point in the history
* docs: 添加包含中心文本的饼图案例

* docs: 添加实例截图
  • Loading branch information
iamzone authored Nov 2, 2023
1 parent 05e408a commit 5f6bec9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion site/examples/general/pie/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*uQh-RryfSfUAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "pie-donut-text.ts",
"title": {
"zh": "饼图, 中心文本",
"en": "Pie Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*vQQgQ4d11egAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "donut.ts",
"title": {
Expand All @@ -37,4 +45,4 @@
"screenshot": "https://mdn.alipayobjects.com/mdn/huamei_qa8qxu/afts/img/A*eJQYQZQ_HZQAAAAAAAAAAAAADmJ7AQ"
}
]
}
}
51 changes: 51 additions & 0 deletions site/examples/general/pie/demo/pie-donut-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* A recreation of this demo:
*/
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
height: 640,
padding: 0,
inset: 50,
});

chart.coordinate({ type: 'theta', innerRadius: 0.6 });

chart
.interval()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/79fd9317-d2af-4bc4-90fa-9d07357398fd.csv',
})
.transform({ type: 'stackY' })
.encode('y', 'value')
.encode('color', 'name')
.scale('color', {
palette: 'spectral',
offset: (t) => t * 0.8 + 0.1,
})
.legend(false);

chart
.text()
.style('text', 'Donut')
// Relative position
.style('x', '50%')
.style('y', '50%')
.style('fontSize', 40)
.style('fontWeight', 'bold')
.style('textAlign', 'center');

chart
.text()
.style('text', 'chart')
// Absolute position
.style('x', 640 / 2 - 16)
.style('y', 360)
.style('fontSize', 20)
.style('fontWeight', 'bold')
.style('textAlign', 'center');

chart.render();

0 comments on commit 5f6bec9

Please sign in to comment.