本文关于有展开效果的饼图
要点关注:
- 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")
效果图:
