JavaのAspose.Tasksでガントチャートをレンダリングします

Microsoft Projectを使用すると、ユーザーはガントチャートが表示されるタイムスケールを設定できます。(タイムスケールはガントチャートビューの上部に示されています)。

JavaのAspose.Tasksはこの機能をサポートし、異なるタイムスケール設定でガントチャートをレンダリングできます。ガントチャートは、これらのオプションを使用して1ページの画像にレンダリングできます。

タイムスケールの設定と画像への保存

ImagesAveoptionsクラスのタイムスケールプロパティは、プロジェクトのタイムスケール設定を決定します。タイムスケールはデフォルトで日に設定されます。他のオプションは月と3ヶ月の3番目です。

次のコードサンプル:

  1. プロジェクトファイルを読み取ります。
  2. それぞれの異なるタイムスケール設定を設定します。
  3. ファイルをJPGとしてディスクに保存します。
 1Project Project = new Project( "NewProductDev.mpp");
 2// 1つのページ画像に保存(デフォルトでTimesCale.Days)
 3project.save( "newProductDevdays.jpeg"new ImagesAveOptions(savefileformat.jpeg));
 4// 1ページの画像に保存(TimesCale.ThirdSofMonths)
 5Imagesaveoptions options = new ImagesAveOptions(savefileformat.jpeg);
 6options.settimescale(timescale.thirdsofmonths);
 7project.save( "newProductDevthirdsofmonths.jpeg"options);
 8// 1つのページ画像に保存(TimesCale.Months)
 9options.settimescale(timescale.months);
10project.save( "newProductDevmonths.jpeg"options);

レンダリング中にガントバーを転がす

saveoptions.rollupganttbarsプロパティがtrueに設定されている場合、プロジェクトの要約タスクは、レンダリング時にタスクを考慮に入れて、目に見えるサブタスクによってマークされます。 (task.hidebar = trueの場合、バーはガントチャートにレンダリングされません。)saveoptions.rollupganttbars = falseの場合、サブタスクはとにかく要約タスクに表示されます。また、saveoptions.drawnonworkingtime(default value = true)がfalseに設定されている場合、非操作時間はガントチャートに表示されません。

例1

 1pdfsaveoptions options = new pdfsaveoptions();
 2options.presentationformat = presentionformat.ganttchart;
 3options.fitcontent = true;
 4options.rollupganttbars = false;
 5options.drawnonworkingtime = false;
 6options.pagesize = pagesize.a3;
 7string file = path.combine(common.testdatapath + "rendering \\"filename);
 8string resfile = path.combine(resultfolderfilename.replace( "。mpp" ".pdf"));
 9Project Project = new Project(file); // ProjectReaderなしでプロジェクトを読むことができます。
10project.save(resfileoptions);

例1からの出力

GANNTチャートPDFの例

例2

この例では、saveoptions.rollupganttbars = true、saveoptions.drawnonworkingtime = true、およびtask.hidebar =非表示のタスクのfalse。

1pdfsaveoptions options = new pdfsaveoptions();
2options.setPresentationFormat(PresentionFormat.GanttChart);
3options.setFitContent(true);
4options.setrollupganttbars(false);
5options.setDrawnOnWorkingTime(false);
6options.setPagesize(pagesize.a3);
7Project Project = new Project( "RollUpganttbars.mpp"); // ProjectReaderなしでプロジェクトを読むことができます。
8project.save( "lollupganttbars.pdf"options);

例2からの出力

GanntチャートPDFとしてMPPをエクスポートします

タスクバーでテキストをカスタマイズ

この例では、タスクバーの右側にあるテキストは、Delegateインスタンスによってカスタマイズできます。ここでは、重要なタスクに関するテキストをカスタマイズします。

 1long oneec = 10000000; // microsecond * 10
 2long onemin = 60 * oneec;
 3長い1時間= 60 * onemin;
 4Project Project = new Project();
 5タスクtask1 = project.addtask( "タスク1");
 6タスクタスク2 = project.addtask( "タスク2");
 7double dduration = one -hour * 8.0 * 3.0; // 3日間のタスク
 8タスク1.SetDuration((LONG)DDURATION);
 9タスク1.SetDuration((LONG)DDURATION);
10tasklink link = new TaskLink(task1task2tasklinktype.finishtostart);
11project.addtasklink(link);
12タスクtask3 = project.addtask( "タスク3");
13リソースrsc1 = project.addresource( "リソース1");
14リソースRSC2 = Project.AddResource( "リソース2");
15リソースrsc3 = project.addresource( "リソース3");
16Project.AddresourceAssignment(Task1RSC1);
17project.addresourceassignment(task2rsc2);
18Project.AddresourceasSignment(Task3RSC3);
19saveoptions options = new pdfsaveoptions();
20options.settimescale(timescale.thirdsofmonths);
21barstyle style = new barstyle();
22style.setItemtype(baritemtype.criticaltask);
23style.setBartextConverter(新しいbarstyle.tasktobartextconverter(){
24  @オーバーライド
25  public string invoke(タスクタスク){
26     task + task.getName() + "をreturn crital Path";
27  }
28});
29barstyle style2 = new barstyle();
30style2.setbarcolor(color.darkgray);
31style2.setItemtype(baritemtype.task);
32options.setBarstyles(new ArrayList <Barstyle>());
33options.getBarstyles()追加(スタイル);
34options.getBarstyles()追加(style2);
35project.save( "result2.pdf"options);

セルの内容を調整

テキストは、ganttchartcolumn.stringalignment、resourceviewcolumn.stringalignmentプロパティによって整列することができます。デフォルトによるアライメントは、stringalignment.near(左)です。

 1Project Project = new Project( "renderme.mpp"); //添付のテストプロジェクト
 2saveoptions options = new pdfsaveoptions();
 3options.settimescale(timescale.months);
 4options.setView(projectView.getDefaultGanttChartView());
 5ganttchartcolumn col =(ganttchartcolumn)options.getView()getColumns()get(2); // as ganttchartcolumn;
 6col.setStringalignment(1); // 中心
 7col =(ganttchartcolumn)options.getView()getColumns()get(3);
 8col.setStringalignment(2); // 遠い
 9col =(ganttchartcolumn)options.getView()getColumns()get(4);
10col.setStringalignment(2); // 遠い
11project.save( "result ganttchart.pdf"options);
12options.setPresentationFormat(PresentionFormat.Resourcesheet);
13ResourceViewColumn col1 =(ResourceViewColumn)options.getView()getColumns()get(2);
14col1.setsstringalignment(1);
15col1 =(ResourceViewColumn)options.getView()getColumns()get(3);
16col1.setStringalignment(2);
17col1 =(ResourceViewColumn)options.getView()getColumns()get(4);
18col1.setStringalignment(2);
19project.save( "result Resourcesheet.pdf"options);

ガントチャートバーのカラーグラデーションの変更

Microsoft Projectを使用すると、ユーザーはGradient Colorsを使用してGanttチャートの出力をレンダリングできます。同じ機能は、次のサンプルコードに示すように、Aspose.Tasksによって提供されます。

1Project Project = new Project( "NewProductDev.mpp");
2saveoptions options = new Xamloptions();
3options.setUseGradientBrush(false);
4project.save( "solid.xaml"options);
5options.setUseGradientBrush(true);
6project.save( "gradient.xaml"options);

ガントチャートビューの開始日を設定

PRJクラスによって公開されたTimesCalestartプロパティにより、Ganttチャートビューの開始日を設定できます。ただし、保存されたファイルが最大化されたウィンドウモードでMSPによって開かれた場合、タイムスケールの開始日は一致しません。

1Project Project = new Project( "rel_constr.mpp");
2project.set(prj.timescale_startnew Date(11523));
3project.save( "temp.mpp"savefileformat.mpp);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.