首页 > 其他分享 >react中绘制饼图基础例子

react中绘制饼图基础例子

时间:2023-11-21 14:38:27浏览次数:26  
标签:绘制 interval chart value data react 例子 type

使用interval标记和theta坐标系来绘制饼图

 radius:标签相对于饼图圆心的距离

.label()中的text 指定了一个回调函数,可以设置标签,其中d是当前项数据,i是当前项的索引,data是全部的数据,注意回调函数要有返回值。

实现效果:

 

import { Chart } from '@antv/g2'
import React from 'react'


const data = [
    { type: '分类一', value: 27 },
    { type: '分类二', value: 25 },
    { type: '分类三', value: 18 },
    { type: '分类四', value: 15 },
    { type: '分类五', value: 10 },
    { type: '其他', value: 5 }
]
export default function Pie() {
    React.useEffect(() => {
        const chart = new Chart({
            container:'pie-container'
        })
        // 写在视图层级  chart.interval().coordinate()写在mark层级
        chart.coordinate({ type: 'theta' })
        chart.interval()
            .transform({type:'stackY'})
            .data(data)
            .encode('y', 'value')
            .encode('color', 'type')
            .label({
                // 指定绑定的字段
                text: (d, i, data) => { return d.value<10 ? '' : d.type },  // d当前项  i当前项的索引  data 数据
                radius: 0.5, 
                fontSize: 10,
                fontWeight: 'bold'
            })
        chart.render()
    },[])
    return (
        <div id="pie-container">
        </div>
    )
}

标签:绘制,interval,chart,value,data,react,例子,type
From: https://www.cnblogs.com/hyxxl/p/17846404.html

相关文章

  • 7段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#画数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#画单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.r......
  • 7段数码管绘制
       ......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):#......
  • vue3 ts 父子 组件小例子
    <project-tabref="projectTabRef"v-model="form.projectVO":data="parentToChild"@update="updateHandler"></project-tab>//引用组件constProjectTab=defineAsyncComponent(()=>import('./tabsProject.......
  • 7段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#绘制数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#绘制单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.right(90)def......
  • 7段数码管绘制
    要求:画出,系统时间。具体包括:小时,分,秒,星期。 importturtleastimporttimea=time.strftime('%a',time.localtime())ifa=='Mon':c=1elifa=='Tue':c=2elifa=='Wed':c=3elifa=='Thu':c=4elif......
  • 7段数码管绘制
    7段数管码代码运行22信计1班34号代码#e7.2DrawSevenSegDisplay.pyimportturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle......
  • 七段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):#根据......
  • 7段数码管绘制
    importtimeimportturtleasttdefdrawGap():tt.penup()tt.fd(5)defdrawLine(draw):drawGap()if(draw):tt.pendown()else:tt.penup()tt.fd(50)drawGap()tt.right(90)defdrawDate(date):tt.pencolor("red"......
  • revit中绘制标高轴网
    1、轴网操作:添加标高需要在平面视图中添加,添加完成后可重命名,对齐等主要使用场景:主要用于测试模型审查的碰撞审查点的轴网取值,主要要模拟的场景在轴网内部和边界处--根据实际业务需求得出 2、标高操作:轴网需要在立面视图中添加,添加完成后可重命名、对齐等主要使用场景:主......