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

来源:互联网 发布:sqlyog导入sql文件报错 编辑:程序博客网 时间:2024/05/22 03:22

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


要点关注:

  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")

效果图:



原创粉丝点击