Configure Visio TimeLine Shapes

Set Milestone Shape Properties

Aspose.Diagram allows developers to set milestone properties. This article shows how to set the milestone date, date format, auto update flag and type.

Setting Milestone Date, Date Format, Auto Update Flag and Type

The MilestoneHelper class takes a Shape object while initializing the MilestoneHelper object. The code example in this article sets the milestone date, date format, auto update flag and milestone type properties.

The milestone before update

todo:image_alt_text

</p>

The milestone after update. Note the changed date format.

todo:image_alt_text

</p>

The process for updating the milestone date, date format, auto update flag and milestone type:
  1. Load a diagram.
  2. Find a particular shape.
  3. Initialize the MilestoneHelper object.
  4. Set a milestone date.
  5. Set the milestone date format.
  6. Set an auto update flag.
  7. Set the milestone type
  8. Save the Visio drawing to any supported format.

Set Milestone Programming Sample

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SetMilestoneProps.class);
// Load diagram
Diagram diagram = new Diagram(dataDir + "DrawingTimeLine.vsdx");
int shapeid = 22;
// Get timeline shape
Shape milestone = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid);
// Initialize MilestoneHelper object
MilestoneHelper milestoneHelper = new MilestoneHelper(milestone);
// Set milestone date
milestoneHelper.setMilestoneDate(new DateTime(2014, 10, 21));
// Set date format
milestoneHelper.setDateFormat(21);
// Set auto update flag
milestoneHelper.setAutoUpdate(true);
// Set milestone type
milestoneHelper.setType(6);
// Save to VDX format
diagram.save(dataDir + "SetMilestoneProps_Out.vsdx", SaveFileFormat.VSDX);

Table of date format values:

Value Format String
0 dddd, yyyy-M-d
1 yyyy-MM-dd
2 yy-MMM-d
3 yyyy/M/d
4 yy-MMM.-d
5 d MMMM yyyy
6 yy-M
7 MMM-yy
8 MMMM d, yyyy
9 MMM d, yyyy
10 M-d-yy
11 M-d
12 d MMMM, yyyy
13 d MMM, yyyy
14 d-M-yy
15 d-M
16 yy-M-d
17 yyyy-M-d
18 M-yy
19 M-yyyy
20 MMMM yyyy
21 MMMM yy
22 MMM yyyy
23 MMM yy
24 yy
25 yyyy
26 d
27 MMMM
28 MMM
29 M

Set Time Period and Date Format of Timeline Shape

Aspose.Diagram allows developers to configure the timeline programmatically. This explains how to adjust the time period and date format of timeline shapes (block, line, ruler, divided, or cylindrical).

Setting Time Period and Date Format

The TimeLineHelper class takes a Shape object when initializing the TimeLineHelper object. The code example in this article sets the time period start, end and date format values.

The time period tab of the Visio Configure Timeline dialog

todo:image_alt_text

The time format tab of the Visio Configure Timeline dialog

todo:image_alt_text

Input diagram

todo:image_alt_text

The diagram after the values have been changed

todo:image_alt_text

The process for updating time period start, end and date format is:
  1. Load a diagram.
  2. Find a particular shape.
  3. Initialize the TimeLineHelper object.
  4. Set the time period start.
  5. Set the time period end.
  6. Set a date format.
  7. Save the Visio drawing to any supported format.

Set Time Period and Date Programming Sample

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConfigureTimeLine.class);
// Load diagram
Diagram diagram = new Diagram(dataDir + "DrawingTimeLine.vsdx");
int shapeid = 1;
// Get timeline shape
Shape timeline = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid);
// Initialize TimeLineHlper object
TimeLineHelper timelineHelper = new TimeLineHelper(timeline);
// Set start time
timelineHelper.setTimePeriodStart(new DateTime(2014, 12, 21));
// Set end time
timelineHelper.setTimePeriodFinish(new DateTime(2015, 2, 19));
// Set date format
//timelineHelper.setDateFormatForBE(21);
// Set date format for intm of timeline shape
//timelineHelper.setDateFormatForIntm(21);
// Or
// Set date format string for start and finish of timeline shape
timelineHelper.setDateFormatStringForBE("yyyy-MM-dd");
// Set date format string for intm of timeline shape
timelineHelper.setDateFormatStringForIntm("yyyy-MM-dd");
// Save to VDX format
diagram.save(dataDir + "ConfigureTimeLine_Out.vsdx", SaveFileFormat.VSDX);

Table of date format values:

Value Format String
0 dddd, yyyy-M-d
1 yyyy-MM-dd
2 yy-MMM-d
3 yyyy/M/d
4 yy-MMM.-d
5 d MMMM yyyy
6 yy-M
7 MMM-yy
8 MMMM d, yyyy
9 MMM d, yyyy
10 M-d-yy
11 M-d
12 d MMMM, yyyy
13 d MMM, yyyy
14 d-M-yy
15 d-M
16 yy-M-d
17 yyyy-M-d
18 M-yy
19 M-yyyy
20 MMMM yyyy
21 MMMM yy
22 MMM yyyy
23 MMM yy
24 yy
25 yyyy
26 d
27 MMMM
28 MMM
29 M

Refresh Milestones on the Timeline in Visio

Aspose.Diagram allows developers to adjust milestones on the timeline shapes (block, line, ruler, divided, or cylindrical) according to the time period change.

Refresh Milestones on the Timeline using TimeLineHelper class

The RefreshTimeLine method exposed by the TimeLineHelper class can be used to revive milestones on the timeline.

The code below shows how to:

  1. load a sample diagram.
  2. get a timeline shape.
  3. initialize the TimeLineHelper object.
  4. set the time period start.
  5. set the time period end.
  6. set date format (optional).
  7. call RefreshTimeLine method of the TimeLineHelper object.
  8. save diagram

Refresh Milestones using TimeLineHelper Programming Sample

Use the following code in your Java application to revive milestones on the timeline using Aspose.Diagram for Java.

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RefreshTimeLine.class);
// Load diagram
Diagram diagram = new Diagram(dataDir + "DrawingTimeLine.vsdx");
int shapeid = 1;
// Get timeline shape
Shape timeline = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid);
// Initialize TimeLineHlper object
TimeLineHelper timelineHelper = new TimeLineHelper(timeline);
// Set start time
timelineHelper.setTimePeriodStart(new DateTime(2014, 12, 21));
// Set end time
timelineHelper.setTimePeriodFinish(new DateTime(2015, 2, 19));
// Set date format
timelineHelper.setDateFormatForBE(21);
//revive milestones on the timeline
timelineHelper.refreshTimeLine();
// Save to VDX format
diagram.save(dataDir + "RefreshTimeLine_Out.vsdx", SaveFileFormat.VSDX);

Refresh Milestones on the Timeline using MilestoneHelper class

The RefreshMilestone method exposed by the MilestoneHelper class can be used to refresh milestones on the timeline.

The code below shows how to:

  1. load a sample diagram.
  2. get a timeline shape.
  3. add Shape in Visio diagram using AddShape method.
  4. initialize the MilestoneHelper object.
  5. set Milestone Date.
  6. set Milstone’s IsAutoUpdate property to true.
  7. call RefreshMilestone method of the MilestoneHelper object.
  8. save diagram

Refresh Milestones using MilestoneHelper Programming Sample

Use the following code in your Java application to refresh milestones on the timeline using Aspose.Diagram for Java.

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RefreshMilestoneWithMilestoneHelper.class);
String pageName = "Page-1";
////////////// Modify time line ///////////
DateTime startDate = new DateTime(2015, 8, 1);
DateTime endDate = new DateTime(2016, 6, 1);
DateTime fisYear = startDate;
//Load a diagram
Diagram diagram = new Diagram(dataDir + "DrawingTimeLine.vsdx");
//Get page
Page page = diagram.getPages().getPage(pageName);
long timelineId = 1;
Shape timeline = diagram.getPages().getPage(pageName).getShapes().getShape(timelineId);
double xpos = timeline.getXForm().getPinX().getValue();
double ypos = timeline.getXForm().getPinY().getValue();
// Add milestone
String milestoneMasterName = "2 triangle milestone";
//Add Master
diagram.addMaster(dataDir + "Timeline.vss", milestoneMasterName);
//Add Shape in Visio diagram using AddShape method
long milestoneShapeId = diagram.addShape(xpos, ypos, milestoneMasterName, 0);
//Get the shape based on ID
Shape milestone = page.getShapes().getShape(milestoneShapeId);
//Instantiate MilestoneHelper object
MilestoneHelper milestoneHelper = new MilestoneHelper(milestone);
//Set Milestone Date
milestoneHelper.setMilestoneDate(new DateTime(2015, 8, 1));
//Set IsAutoUpdate to true
milestoneHelper.setAutoUpdate(true);
//RefreshMilesone of timeline shape
milestoneHelper.refreshMilestone(timeline);
//Save Visio file
diagram.save(dataDir + "RefreshMilestone_Out.vsdx", SaveFileFormat.VSDX);