The Gantt charts are used to represent the schedule of sequence of tasks in a project. To plot Gantt charts, you need to have the start and end times of a task.
The walkthrough is split into the following activities:
- Creating an ActiveReports project in Visual Studio
- Connecting the report to a data source
- Adding a dataset
- Adding a chart data region and define plots
- Configuring the appearance of the chart
- Viewing the report
Note:
- This walkthrough uses the ScheduleOfTime table from the Schedule database. By default, in ActiveReports, the Schedule.mdb file is located in the [User Documents folder]\GrapeCity Samples\ActiveReports 13\Data folder.
- Although this walkthrough uses Page reports, you can also implement this using RDL reports.
When you complete this walkthrough you get a layout that looks similar to the following at design time and at run time.
Design-Time Layout
Run-Time Layout
To create an ActiveReports project in Visual Studio
- Create a new Visual Studio project.
- In the New Project dialog that appears, select ActiveReports 13 Page Report Application and in the Name field, rename the file as rptGanttChart.
- Click OK to create a new ActiveReports 13 Page Report Application. By default a Page report is added to the project.
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the report to a data source
- In the Report Explorer, right-click the Data Sources node and select the Add Data Source option or select Data Source from the Add button.
- In the Report Data Source Dialog that appears, select the General page and in the Name field, enter a name like ChartData.
- On this page, create a connection to the Schedule database. See Connect to a Data Source for information on connecting to a data source.
To add a dataset
- In the Report Explorer, right-click the ChartData data source node and select the Add Data Set option or select Data Set from the Add button.
- In the DataSet Dialog that appears, select the General page and enter the name of the dataset as ScheduleData.
- On the Query page of this dialog, in the Query field enter the following SQL query.
SQL Query |
Copy Code
|
SELECT Top 5 * from ScheduleOfTime
|
- Click the Validate DataSet icon at the top right hand corner above the Query box to validate the query.
- To obtain end time of the tasks, you need to add a field that calculates end times. Go to Fields tab and add a calculated field EndTime with expression
=DateAdd(DateInterval.Hour, [Hours], [StartTime])
.
- Click OK to close the dialog. Your data set and queried fields appear as child nodes to the data source in the Report Explorer.
To add a chart data region and define plots
- From the toolbox, drag a Chart data region onto the of the report.
- In the Select a Chart Type wizard that appears and select the chart type as Column.
- Right-click on the chart and go to Plot Template > Miscellaneous and select Gantt.
Note that the chart changes to horizontal bar chart, where horizontal axis (AxisType Y) represents time duration that a task needs to finish and each bar (plotted along Vertical axis (AxisType X)) represents a task.
- Select the chart control so that the chart adorners are displayed.
- Right-click the Data Fields adorner and click Add. You see that a field is added.
- Select the field and click the ellipses next to Subfields property to open Complex Fields Collection Editor.
- Set lower value to
=Fields!StartTime.Value
and upper value to =Fields!EndTime.Value
to show Value axis.
- Click OK to save and exit the collection editor.
- Select the chart control so that the chart adorners are displayed.
- Right-click the Category Fields adorner and click Add. You see that category 'Category0' is added.
- Select 'Category0' and set its Expression to
=Fields!Labels.Value
.
To configure the appearance of the chart
- Select Chart and set Pallet to Office.
- Select 'Chart title' on the chart and set Title to 'Schedule'.
- Select Category axis (AxisType X) and set Title to 'Topics'.
- Select Value axis (AxisType Y) and set Title to 'Timeline'.
- Select the Timeline axis and set the label settings as:
Property Name |
Property Values |
Labels>LabelAngle |
-45 |
Title>TitleStyle>Font>FontSize
Specify the template to be displayed for the label. |
10pt |
- Select the Topics axis and set Title>TitleStyle>Font>FontSize to 10 pt.
To view the report
- Click the to view the report at design time.
OR