JAVASCRIPT
VUE
REACT
NODE
ES6
TYPESCRIPT

G2plot饼图数据展示

2021. 08. 05    

g2plot饼图数据展示

import { Pie } from '@antv/g2plot';

const data = [
  { type: '分类一', value: 27 },
  { type: '分类二', value: 25 },
  { type: '分类三', value: 18 },
  { type: '分类四', value: 15 },
  { type: '分类五', value: 10 },
  { type: '其他', value: 5 },
];

const piePlot = new Pie('container', {
  appendPadding: 10,
  data,
  angleField: 'value',
  colorField: 'type',
  radius: 0.9,
  label: {
    type: 'inner',
    offset: '-30%',
    formatter: (item) => {
      console.log(JSON.stringify(item));
      //{"type":"分类一","value":27,"percent":0.27}
      return item.value;
    },
    style: {
      fontSize: 14,
      textAlign: 'center',
    },
  },
  interactions: [{ type: 'element-active' }],
});

piePlot.render();


扫码