文档章节

ChartDirector Python制作多层甘特图

咲晚杍
 咲晚杍
发布于 2013/09/26 14:27
字数 747
阅读 255
收藏 0

在本文中主要是使用ChartDirector的Python版本来创建出多层级的甘特图,而在此次的示例演示中将会包含两个图层,包含计划和实际情况的甘特图,XYChart.addBoxWhiskerLayer 创建的两个图层,使用BaseBoxLayer.setDataWidth来进行在栏的顶部的图层的宽度的设置,以便它不会挡住底部的图层。


具体示例的源代码如下,和大家一起分享分享:

#!/usr/bin/python
from pychartdir import *

# the names of the tasks
labels = ["Market Research", "Define Specifications", "Overall Archiecture",
    "Project Planning", "Detail Design", "Software Development", "Test Plan",
    "Testing and QA", "User Documentation"]

# the planned start dates and end dates for the tasks
startDate = [chartTime(2004, 8, 16), chartTime(2004, 8, 30), chartTime(2004, 9, 13),
    chartTime(2004, 9, 20), chartTime(2004, 9, 27), chartTime(2004, 10, 4),
    chartTime(2004, 10, 25), chartTime(2004, 11, 1), chartTime(2004, 11, 8)]
endDate = [chartTime(2004, 8, 30), chartTime(2004, 9, 13), chartTime(2004, 9, 27),
    chartTime(2004, 10, 4), chartTime(2004, 10, 11), chartTime(2004, 11, 8),
    chartTime(2004, 11, 8), chartTime(2004, 11, 22), chartTime(2004, 11, 22)]

# the actual start dates and end dates for the tasks up to now
actualStartDate = [chartTime(2004, 8, 16), chartTime(2004, 8, 27), chartTime(2004, 9,
    9), chartTime(2004, 9, 18), chartTime(2004, 9, 22)]
actualEndDate = [chartTime(2004, 8, 27), chartTime(2004, 9, 9), chartTime(2004, 9, 27
    ), chartTime(2004, 10, 2), chartTime(2004, 10, 8)]

# Create a XYChart object of size 620 x 280 pixels. Set background color to light
# green (ccffcc) with 1 pixel 3D border effect.
c = XYChart(620, 280, 0xccffcc, 0x000000, 1)

# Add a title to the chart using 15 points Times Bold Itatic font, with white
# (ffffff) text on a dark green (0x6000) background
c.addTitle("Multi-Layer Gantt Chart Demo", "timesbi.ttf", 15, 0xffffff
    ).setBackground(0x006000)

# Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use alternative
# white/grey background. Enable both horizontal and vertical grids by setting their
# colors to grey (c0c0c0). Set vertical major grid (represents month boundaries) 2
# pixels in width
c.setPlotArea(140, 55, 460, 200, 0xffffff, 0xeeeeee, LineColor, 0xc0c0c0, 0xc0c0c0
    ).setGridWidth(2, 1, 1, 1)

# swap the x and y axes to create a horziontal box-whisker chart
c.swapXY()

# Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22, 2004, with ticks
# every 7 days (1 week)
c.yAxis().setDateScale(chartTime(2004, 8, 16), chartTime(2004, 11, 22), 86400 * 7)

# Add a red (ff0000) dash line to represent the current day
c.yAxis().addMark(chartTime(2004, 10, 8), c.dashLineColor(0xff0000, DashLine))

# Set multi-style axis label formatting. Month labels are in Arial Bold font in "mmm
# d" format. Weekly labels just show the day of month and use minor tick (by using
# '-' as first character of format string).
c.yAxis().setMultiFormat(StartOfMonthFilter(), "<*font=arialbd.ttf*>{value|mmm d}",
    StartOfDayFilter(), "-{value|d}")

# Set the y-axis to shown on the top (right + swapXY = top)
c.setYAxisOnRight()

# Set the labels on the x axis
c.xAxis().setLabels(labels)

# Reverse the x-axis scale so that it points downwards.
c.xAxis().setReverse()

# Set the horizontal ticks and grid lines to be between the bars
c.xAxis().setTickOffset(0.5)

# Use blue (0000aa) as the color for the planned schedule
plannedColor = 0x0000aa

# Use a red hash pattern as the color for the actual dates. The pattern is created as
# a 4 x 4 bitmap defined in memory as an array of colors.
actualColor = c.patternColor([0xffffff, 0xffffff, 0xffffff, 0xff0000, 0xffffff,
    0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000,
    0xffffff, 0xffffff, 0xffffff], 4)

# Add a box whisker layer to represent the actual dates. We add the actual dates
# layer first, so it will be the top layer.
actualLayer = c.addBoxLayer(actualStartDate, actualEndDate, actualColor, "Actual")

# Set the bar height to 8 pixels so they will not block the bottom bar
actualLayer.setDataWidth(8)

# Add a box-whisker layer to represent the planned schedule date
c.addBoxLayer(startDate, endDate, plannedColor, "Planned").setBorderColor(
    SameAsMainColor)

# Add a legend box on the top right corner (595, 60) of the plot area with 8 pt Arial
# Bold font. Use a semi-transparent grey (80808080) background.
b = c.addLegend(595, 60, 0, "arialbd.ttf", 8)
b.setAlignment(TopRight)
b.setBackground(0x80808080, -1, 2)

# Output the chart
c.makeChart("layergantt.png")

本文转载自:http://www.evget.com/zh-CN/Info/catalog/18254.html

咲晚杍
粉丝 7
博文 75
码字总数 8143
作品 0
渝中
私信 提问
Web图表开发工具JFreeChart与ChartDirector使用评测

在Web开发中,图形和图表是常用的数据呈现方式,图表能将枯燥的数据生动的表现出来。也许你正接手一个Web图表开发项目,却被Web图表开发工具选型的问题困扰着,要么是价格昂贵,要么就是部署...

咲晚杍
2013/08/21
767
0
ChartDirector创建彩色甘特图

甘特图非常适合用于展示工作进度,而如果把甘特图的进度条以不同的颜色进行区分,将会进一步提高甘特图的可读性。本示例演示用Web图表控件ChartDirector创建彩色的甘特图,这个甘特图中有3个...

咲晚杍
2013/09/24
395
0
ChartDirector python版安装记录

ChartDirector 是一款商业的图表库,有多种语言的版本,使用它做的图表非常的精细漂亮,提供免费版本,但会出现logo信息。网上有很多关于它的破解方法。 下面是ChartDirector python版安装记...

绿悠悠
2010/06/19
1K
2
Qt之自绘制饼图和绘图插件比较

最近在搞绘图方面的工作,说实话C++的第三方绘图库并不算多,总之我了解的有:qtcharts、ChartDirector、qwt、kdchart和QCustomPlot。这几个库各有利弊。 qtcharts:qt5.7之后才开源的模块,...

wangxujun59
10/08
18
0
ChartDirector破解及中文问题解决

ChartDir是一个比Jfreechart还要好的图表工具包,但要收费. ChartDir Project home: http://www.advsofteng.com/ 下一个来试验吧 http://download2.advsofteng.com/chartdir_java.war ------......

红薯
2009/03/06
13.7K
1

没有更多内容

加载失败,请刷新页面

加载更多

sync.Mutex 互斥锁

说明: 互斥锁用来保证在任一时刻,只能有一个例程访问某对象。Mutex 的初始值为解锁状态。Mutex 通常作为其它结构体的匿名字段使用,使该结构体具有 Lock 和 Unlock 方法。Mutex 可...

李琼涛
7分钟前
2
0
自建redis笔记

自建redis笔记 最近在linux安装了一下redis,特做一些笔记! 本文先单节点启动redis,然后再进行持久化配置,在次基础上,再分享搭建主从模式的配置以及Sentinel 哨兵模式及集群的搭建 单节点...

北极之北
10分钟前
2
0
扛住阿里双十一高并发流量,Sentinel是怎么做到的?

Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景 本文介绍阿里开源限流熔断方案Sentinel功能、原理、架构、快速入门以及相关框架比较 基本介绍 1 名词解释 服务限流 :当系统资源...

分布式系统架构
12分钟前
2
0
事假杨晨龙(Z16021)月薪请假单

svn co URL --username xxx-- password yyy ./

桃花飞舞
35分钟前
3
0
当Activity关闭后,网络请求回调的处理

当我们在使用网络请求的时候,一般都是通过回调来获取请求到的数据。对于网络请求的回调需要注意的几个点 比如我们的回调在Activity中处理数据,当我们把Activity关闭后,如果获取到数据时,...

shzwork
36分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部