如何在数据窗口中创建类似甘特图的图表(Powerbuilder)
我想要一个相当简单(且便宜)的解决方案,仅用于演示目的(并且仅用于显示任务持续时间条 - 它们之间没有连接线)。因此,我对购买一些高级自定义控件不感兴趣,例如 this例如。你们有人用过这样的东西吗?有可用的代码示例吗?
I want a rather simple (and cheap) solution, just for presentation purposes (and just to show the task duration bars - no connection lines between them). So, I am not interested in buying some advanced custom control like this for example. Have any of you ever used something like this? Are there any code samples available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会指出 Buck Woolley 的 dwExtreme 站点 获取如何在本机 DataWindow 中制作甘特图的示例。然而,如果你想推出自己的产品,我认为“简单”不会出现在你的未来。事实上,如果有人写了一篇包含完整描述的帖子,我会感到惊喜;我认为这需要几页。 (如果有人证明我错了,我会很高兴。)同时,这里有一些我认为您需要的 DataWindow 基础知识:
我预计这需要大量的工作和时间,并且很可能值得购买该组件(除非您的时间几乎不值钱,这在一些 IT 商店中接近于真的)。
祝你好运,
特里
I would have pointed to Buck Woolley's dwExtreme site for an example of how to do a gantt in native DataWindow. However, "simple" I don't think is in your future if you want to roll your own. In fact, I'll be pleasantly surprised if someone writes a posting that includes a full description; I think it would take pages. (I'd be happy if someone proved me wrong.) In the meantime, here are some DataWindow basics I think you would need:
I'd expect this to be a lot of work and time, and very likely to be worth the purchase the component (unless your time is valued at next to nothing, which in some IT shops is close to true).
Good luck,
Terry
(来源:illudium.com)
您可以制作一个简单的甘特图带有堆积条形图的图表(画家中的 BarStacked (5))。诀窍是创建一个虚拟系列,将条形图间隔到您想要的位置,并使虚拟条形图的颜色与图形的背景颜色 (BackColor) 相同。事实证明,您还需要另一个具有较小值的虚拟系列来放置在轴上。否则,当您更改执行间距的条的颜色时,轴线会被切断。我发现 0.04 非常适合这个值。
创建数据窗口
(假设您熟悉数据窗口向导。有关在数据窗口中创建图形的更多信息,请参阅《PowerBuilder 用户指南》)
单击新对象向导的图标。使用外部数据源创建图形数据窗口。创建列任务类型字符串(20)、服务类型字符串(1) 和天类型数字。将类别设置为任务列,将值设置为天数列。单击“系列”按钮并为该系列选择“ser”。不要理会标题,选择堆积条形图类型。当画家打开时,保存数据窗口。在 Painter 的“常规”选项卡上,将“图例”更改为“无”(0)。在“轴”选项卡上,选择“类别”轴,然后将排序设置为“未排序”(0)。选择“值”轴,然后将排序设置为“未排序”(0)。选择系列轴并将排序设置为升序 (1)。保存数据窗口。
创建窗口
创建一个窗口并放置一个 DataWindow 控件 dw_1。将数据对象设置为图形数据窗口。将以下内容放置在 open 事件中(如果使用 PFC,则将其放置在 pfc_postopen 中)。
您将加载图表的数据,其中注释为
// LOAD DATA HERE
编写 graphcreate 事件脚本
将新事件添加到 dw_1。选择 pbm_dwngraphcreate 作为事件 ID。我喜欢通过删除 pbm_dwn 前缀来命名这些事件,因此我使用 graphcreate。将以下代码添加到事件中。
图表数据
按照所需的相反顺序加载类别数据。对于每个任务,插入 3 行并将系列分别设置为 a、b 和 c。对于每个任务中的系列 a,设置一个较小的值。我用的是0.04。你可能需要尝试一下。对于每个任务中的系列 b,设置开始前的天数。对于系列 c,设置天数。下面是示例数据窗口中的数据。
示例数据窗口
下面是导出格式的示例数据窗口的源代码。您应该能够导入到任何版本 >= PB 10。复制代码并将其粘贴到具有 SRD 扩展名的文件中,然后导入它。
(source: illudium.com)
You can make a simple Gantt chart with a Stacked Bar Graph (BarStacked (5) in the painter). The trick is to create a dummy series to space the bar out where you want it and make the dummy bar the same color as the graph's background (BackColor). It turns out you also need another dummy series with a small value to sit on the axis. Otherwise when you change the color of the bar that's doing the spacing, the axis line gets cut off. I found that .04 works well for this value.
Create the DataWindow
(This assumes familarity with the DataWindow Wizard. Refer to the PowerBuilder User's Guide for more information on creating graphs in DataWindows)
Click the icon for the new object wizard. Create a Graph DataWindow with an External data source. Create columns task type string(20), ser type string(1), and days type number. Set the Category to the task column and the Values to the days column. Click the Series button and select ser for the series. Don't bother with the title, and select the Stacked Bar graph type. When the painter opens, save the DataWindow. On the General tab in the Painter, change the Legend to None (0). On the Axis tab, select the Category axis, then set the sort to Unsorted (0). Select the Value axis then set the sort to Unsorted (0). Select the Series axis and set the sort to Ascending (1). Save the DataWindow.
Create the Window
Create a window and place a DataWindow control, dw_1. Set the data object to your graph DataWindow. Place the following in the open event (or pfc_postopen if using PFC).
You would load the data for your chart where the comment says
// LOAD DATA HERE
Script the graphcreate Event
Add an new event to dw_1. Select pbm_dwngraphcreate for the Event ID. I like to name these events by removing the pbm_dwn prefix so I use graphcreate. Add the following code to the event.
Data for the Graph
Load the data with the categories in the reverse order of what you want. For each Task, insert 3 rows and set the series to a, b, and c, respectively. For series a in each task, set a small value. I used 0.04. You may have to experiment. For series b in each task, set the number of days before start. For series c, set the number of days. Below is the data in the sample DataWindow.
Sample DataWindow
Below is the source for a sample DataWindow in export format. You should be able to import into any version >= PB 10. Copy the code and paste it into a file with an SRD extension, then import it.