ChartDirector 5.0 for python 笔记【9】Exploded Pie Chart

本文关于有展开效果的饼图


要点关注:

  1. PieChart.setSectorStyle设置扇区边缘厚度。

源代码:
#-*-encoding:utf-8 -*-
from pychartdir import *
setLicenseCode("SXZVFNRN9MZ9L8LGA0E2B1BB");#这个是注册,防止有logo产生

data = [21, 18, 15, 12, 8, 24]
labels = ["Labor", "Licenses", "Taxes", "Legal", "Facilities", "Production"]
colors = ['0x66aaee', '0xeebb22', '0xbbbbbb', '0x8844ff', '0xdd2222', '0x009900']
c = PieChart(600, 360)

# 使用白色调色板,这样默认的文本和线条就是白色
c.setColors(whiteOnBlackPalette)

#用垂直梯度色作为背景,从深蓝色到蓝色。
c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), '0x000066', '0x0000cc'))
c.setRoundedFrame('0xffffff', 20)
c.setDropShadow()
c.addTitle("Exploded Pie Chart Demonstration", "timesbi.ttf", 18).setMargin2(0, 0,
    16, 0)

c.setPieSize(300, 195, 110)
c.setData(data, labels)

#设置扇区颜色
c.setColors2(DataColor, colors)

# 设置扇区阴影和5像素边缘
c.setSectorStyle(LocalGradientShading, '0xbbffffff', 5)

#侧边标签方法
c.setLabelLayout(SideLayout)

t = c.setLabelStyle("arialbd.ttf", 10, '0x000000')
t.setBackground(SameAsMainColor, Transparent, softLighting(Right, 0))
t.setRoundedCorners(8)

c.setLabelFormat(
    "<*block,halign=center,width=110*>{label}\n<*font=arial.ttf,size=8*>US$ " \
    "{value}M ({percent}%)<*/*>")

# 将所有扇区从中心展开10像素
c.setExplode(-1, 10)
c.makeChart("explodedpie.png")

效果图:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值