使用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()

产生:

https://chart.googleapis.com/chart?chxt=x,y&chds=0,15&chco=FFFFFF00,CC0000FF,00CC00FF,0000CCFF&chbh=46,4,0&chtt=Test%20Chart&chxl=0:|20/02|21/02|22/02|23/02|24/02|25/02|26/02|27/02|28/02|01/03|02/03|03/03|04/03|05/03|06/03|07/03|1:|Future%20Task|On%20Time%20Task|Late%20Task&chdl=|Late|On%20Time|Upcoming&chd=t:0,5,8|5,0,0|0,3,0|0,0,7&chg=6.66666666667,0&chm=r,4D89F933,0,0,0.466666666667&chs=650x200&cht=bhs

功能

  • 可选的进度指示器会对图表的已用区域进行着色。
  • 灵活的图表宽度和高度。
  • 使用css规则指定任务颜色
  • 灵活地使用DATETME.DATA对象或元组指定日期。
  • 生成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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何从旧的ArrayList<ArrayList<Integer>>创建新的ArrayList而不更改旧的?   java JBoss 7 |从随机线程写入jndi   java如何在数据库中有空值的JPA实体中迭代联接列   java Android应用程序在setContentView上崩溃   java如何在表单中预先填充文本字段,其中包含数据库中的信息。jsp?   来自R.raw的java Android文件阅读器。文件   如何将多个WAR(或Java Web应用程序,特别是使用Spring MVC)嵌入到一个承载另一个WAR的网页中?   java动态更新Jlist   gwt分页大结果集Java的最佳方式是什么   JavaCDI:为什么我的瞬态字段被序列化?   使用JAXB更新java XML模板文件   java getGraphics()返回空值   扩展javax的java类。ws。rs.core。无法将应用程序强制转换为Servlet   java方法可能无法在异常时关闭流   公共类的表达式的java非法开始   java年轻一代GC在EXT根扫描上花费了太多时间   使用CXF和具有未发布元数据的WSDL的java