Tutorial 19: Gantt chart sample
« on: February 04, 2016, 02:57:59 PM »
This sample will draw a standard Gantt chart.
 
A Gantt chart is a kind of horizontal bars chart. Each horizontal bar represents a task in a project and is drawn on a date-time x-axis. A bar shows when a task starts, ends and optionally the percentage of completion for that task (indicated by a black line in the middle of the bar).

Furthermore, it's possible to draw a vertical line which usually equals to the current date. Those taks to the left of that line are in the past, eg. already started (or should have), and those to the right are in the future.
 
Steps:

1. Create a new Windows application project (VB.NET)
2. Add Crossing Charts Library to the toolbox pallete and drag it to Form1.
3. Copy and paste de following code:

Note: the code in the Form1_Load event could be used in ASP.NET applications as well.

Code: [Select]
Imports CrossingChartsLibrary
Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim sf As New SeriesFactory
      ' Add several demo tasks specifying start date, end date and % completed
      sf.AddTask(#1/1/2007#, #1/15/2007#, 0.55)
      sf.AddTask(#1/16/2007#, #1/31/2007#, 0.3)
      sf.AddTask(#2/1/2007#, #2/25/2007#, 0.5)
      sf.AddTask(#2/8/2007#, #3/29/2007#, 0.85)
      sf.AddTask(#4/8/2007#, #5/29/2007#, 0)
      sf.AddTask(#5/8/2007#, #6/29/2007#, 0)
      sf.AddTask(#6/8/2007#, #7/29/2007#, 0)
      sf.AddTask(#6/16/2007#, #10/18/2007#, 0)
      sf.AddTask(#3/9/2007#, #7/22/2007#, 0)
      With CrossingCharts1
         .Title = "My test project"
         .Style = STYLE2D3D.STYLE2D_GANTT
         .ShowLegend = False
         .ShowDataTable = False
         .ShowValues = False
          ' Assign tasks to the chart:
         .Series = sf.Series       ' Assign tasks to the chart
         .SeriesColor = New Color() {Color.Yellow}   ' Color for the tasks
         .ItemsLegend = New String() {"Task 1", "Task 2", "Task 3", "Task 4", "Task 5", "Task 6", "Task 7", "Task 8", "Task 9"}   ' Name of the tasks
         .YAxisTitle = "Tasks"     ' Title for all tasks
          ' X-axis configuration:
         .ShowXAxis = True
         .XAxisTitle = "Time"
         .ShowDividersX = True
         .XAxisLabelsRotated = True
          ' Additional configuration:
         .ValuesFormat = "p0"   ' Show value as a percentage without decimals
         .ShowSurface = True    ' Show past time filled with color
         .GanttSetToday = #5/15/2007#   ' Set "Today" line date position
         .GanttSetTodayLabel = "Today"
         .RefreshChart()
      End With
   End Sub
End Class

Results:

« Last Edit: February 16, 2016, 09:32:11 AM by CrossingCharts »