饼图

源码
/**
 * A recreation of this demo: https://observablehq.com/@d3/pie-chart
 */
import { Chart } from '@antv/g2';

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

chart.options({
  type: 'interval',
  coordinate: { type: 'theta' },
  transform: [{ type: 'stackY' }],
  data: {
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/79fd9317-d2af-4bc4-90fa-9d07357398fd.csv',
  },
  encode: { y: 'value', color: 'name' },
  style: { stroke: 'white' },
  scale: {
    color: {
      palette: 'spectral',
      offset: (t) => t * 0.8 + 0.1,
    },
  },
  labels: [
    {
      text: 'name',
      radius: 0.8,
      fontSize: 10,
      fontWeight: 'bold',
    },
    {
      text: (d, i, data) => (i < data.length - 3 ? d.value : ''),
      radius: 0.8,
      fontSize: 9,
      dy: 12,
    },
  ],
  animate: { enter: { type: 'waveIn' } },
  legend: false,
});

chart.render();
全站搜索
文档与示例输入关键词开始搜索

输入关键词,查找文档、API 与示例

↑↓选择↵打开Esc关闭