使用google charts api生成甘特图
googlegantt的Python项目详细描述
作者:亚当·巴德,http://adambard.com/
此API旨在让您轻松快速地创建甘特图 使用google图表api的图表。您可以将它们保存为图像或 只需生成一个url。
只要你想用天来衡量,它就会膨胀
生成这样一个图表的方法很大程度上受到这个post的影响 戴夫·戈利希。谢谢,戴夫。
快速入门示例
from googlegantt import GanttChart, GanttCategory gc = GanttChart('Test Chart', width=650, height=200, progress=(2011, 02, 27)) on_time = GanttCategory('On Time', '0c0') late = GanttCategory('Late', 'c00') upcoming = GanttCategory('Upcoming', '00c') t1 = gc.add_task('Late Task', (2011, 02, 20), (2011, 02, 25), category=late) t2 = gc.add_task('On Time Task', depends_on=t1, duration=3, category=on_time) t3 = gc.add_task('Future Task', depends_on=t2, duration=7, category=upcoming) url = gc.get_url() image = gc.get_image()
产生:
功能
- 可选的进度指示器会对图表的已用区域进行着色。 灵活的图表宽度和高度。
- 使用css规则指定任务颜色
- 生成google图表url或png图像(需要PIL)。
- 从任务自动计算日期跨度。
班级
创建图表涉及到三个主要类。
甘特哈特
GanttChart(标题,[**kwargs])
Produce a Gantt Chart.
Keyword Arguments:
- width The width of the chart.
- height The height of the chart.
- progress A date representing the current time, to produce a shaded ‘elapsed’ region.
Example initialization:
gc = GanttChart('Test Chart', width=600, height=200, progress=(2011, 02, 27))
方法:
- ganttchart.get_url()获取图表的谷歌图表URL,以便直接访问
- GanttChart.get_image()获取要操作的PIL图像对象
- ganttchart.get_image(保存路径)将.png图像保存到save_path
甘特分类
在一般用法中是可选的。用颜色和标题表示一类任务。
ganttcategory(title[,color])
Produce a category object with a given color. Color is specified using a hex string, and will be converted to an 8-byte rgba hex color string expected by Google Charts from any of the following formats:
- 3-byte, e.g. ‘f00’ => ‘FF0000FF’
- 4-byte, e.g. ‘f00c’ => ‘FF0000CC’
- 6-byte, e.g. ‘ff0000’ => ‘FF0000FF’
- 8-byte
甘特塔斯克
表示图表中的单个条形图。必须有指定的开始和结束日期,尽管 这些可以用不同的方法计算。
ganttask(title[,start_date=None,end_date=None[,**kwargs]])
Keyword Arguments:
- start_date The start date of the task
- end_date The end date of the task
- duration The duration, in days, of the task. May be used instead of end_date
- depends_on A GanttTask that must be completed before this one can begin. May be used instead of start_date
- category A GanttCategory to apply to this task.
- color A quick way to specify color. Don’t use this when you have categories declared, you will get blank legend entries.
Either start_date or depends_onmust be specified. Same with end_date and duration.
If both start_date and depends_on are specified, depends_on is used.
If both end_date and duration are specified, duration is used.
更多信息
有关详细信息,请查看gantt.py文件中的doctests。
许可证
版权所有(c)2011 Adam Bard(adam bard.com)
根据麻省理工学院许可证获得许可:http://www.opensource.org/licenses/mit-license