ChartDirector 5.0 for python 笔记【8】Pie Chart with Legend 下篇
2012-01-08 15:06
489 查看
怎样添加图例到一个饼图中? 下篇
要点关注:
BaseChart.linearGradientColor定义梯度颜色,再使用BaseChart.setBackground来设置它以应用。
BaseChart.setRoundedFrame设置整体圆润框架效果
BaseChart.setDropShadow设置柔和下落阴影
BaseChart.setColors设置扇区颜色
PieChart.setSectorStyle设置扇区梯度阴影
源代码:
注:代码60行左右的部分涉及到了CDML ,在
笔记【10】CDML标记语言 中有介绍。
效果图:
这已经是一个有点美丽的饼图了有没有!
要点关注:
BaseChart.linearGradientColor定义梯度颜色,再使用BaseChart.setBackground来设置它以应用。
BaseChart.setRoundedFrame设置整体圆润框架效果
BaseChart.setDropShadow设置柔和下落阴影
BaseChart.setColors设置扇区颜色
PieChart.setSectorStyle设置扇区梯度阴影
源代码:
注:代码60行左右的部分涉及到了CDML ,在
笔记【10】CDML标记语言 中有介绍。
#-*-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, 320) c.setBackground(c.linearGradientColor(0, 0, 0, 100, '0x99ccff', '0xffffff'), '0x888888') c.setRoundedFrame() c.setDropShadow() #设置图表标题。标题上方留出16像素空白 c.addTitle("Pie Chart With Legend Demonstration", "timesbi.ttf", 18).setMargin2(0, 0, 16, 0) c.setPieSize(160, 165, 110) # 画3D饼图,厚度为25像素 c.set3D(25) c.setData(data, labels) #设置扇区颜色 c.setColors2(DataColor, colors) #给扇区设置梯度阴影效果 c.setSectorStyle(LocalGradientShading) # 使用侧边标签布局方法,使标签距离饼图16像素 c.setLabelLayout(SideLayout,16) # 设置只显示扇区编号 c.setLabelFormat("{={sector}+1}") #设置标签样式。 c.setLabelStyle("arialbd.ttf", 10).setBackground(Transparent, '0x444444') #生成图例栏对象b,左侧中部坐标(300,175),并设置字体arial,加粗倾斜,字体大小。 b = c.addLegend(330, 175, 1, "arialbi.ttf", 10) #设置左对齐。 b.setAlignment(Left) #设置图例背景和圆角效果 b.setBackground(Transparent, '0x444444') b.setRoundedCorners() # 设置图例栏边距16像素,图例内容行间距5像素 b.setMargin(16) b.setKeySpacing(0, 5) #设置图例各项内容图标无边缘。 b.setKeyBorder(SameAsMainColor) b.setText( #表示图例实体的各部分要靠顶对齐 #显示扇区编号,然后往后tab一个22像素距离 "<*block,valign=top*>{={sector}+1}.<*advanceTo=22*>"\ #120像素块来展示label "<*block,width=120*>{label}<*/*>"\ #40像素块来展示百分比,而且是右对齐 "<*block,width=40,halign=right*>{percent}<*/*>%") c.makeChart("legendpie2.png")
效果图:
这已经是一个有点美丽的饼图了有没有!
相关文章推荐
- ChartDirector 5.0 for python 笔记【2】Simple Pie Chart
- ChartDirector 5.0 for python 笔记【4】Multi-Depth Pie Chart
- ChartDirector 5.0 for python 笔记【3】3D Pie Chart
- ChartDirector 5.0 for python 笔记【6】Circular Label Layout
- ChartDirector 5.0 for python 笔记【5】Side Label Layout
- ChartDirector 5.0 for python 笔记【1】环境介绍和搭建
- ChartDirector 5.0 for python 笔记【0】目录概览
- ChartDirector 5.0 for python 笔记【7】Pie Chart with Legend 上篇
- ChartDirector 5.0 for python 笔记【11】Icon Pie Chart 上篇
- ChartDirector 5.0 for python 笔记【9】Exploded Pie Chart
- ChartDirector 5.0 for python 笔记【10】CDML 标记语言
- 【论文笔记】Leveraging Datasets with Varying Annotations for Face Alignment via Deep Regression Network
- Vim 7.4.1952 with Python/Ruby/Lua/Perl/C Syntax built for Ubuntu 16.04 x86_64
- 再读《Parallel Programming with Python》并作笔记
- OpenCV学习笔记(六十二)——《OpenCV Computer Version with Python》阅读摘要
- [论文笔记] SOA Middleware Support for Service Process Reconfiguration with End-to-End QoS Constraints (ICWS 2009)
- 9、TX2学习笔记--Building OpenCV for Tegra with CUDA
- Python Programming with the Java(TM) Class Libraries: A Tutorial for Building Web and Enterprise App
- Python中ValueError: invalid literal for int() with base 10 的实用解决办法
- 【python学习笔记】python if和for的多种写法