Tutorial 20: Create a PDF Report Sheet
« on: February 04, 2016, 03:00:44 PM »
This is a sample of CreatePDF_ReportSheet() method. This method was implemented to get a full page, portrait report of any chart. It calculates appropiates dimensions so legend and datatable fit without any distortion of the chart.
 
CreatePDF_ReportSheet is very useful when there's a lot of data and you want to print both chart and data.
 
Steps:

1. Create a new ASP.NET application project (VB.NET)
2. Add a reference to Crossing Charts Library and to System.Windows.Forms (this one is necessary for the library to operate on web environments)
3. Replace the code of the default web page (default.aspx) with the following one.
4. Run!

Code: [Select]
Imports CrossingChartsLibrary
Imports System.Drawing
Partial Public Class _Default
  Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Dim oChart As New CrossingCharts
  Dim sf As New SeriesFactory
  sf.AddTask(#1/1/2007#, #1/15/2007#, 0.1)
  sf.AddTask(#1/16/2007#, #1/31/2007#, 0.1)
  sf.AddTask(#2/1/2007#, #2/25/2007#, 0.85)
  sf.AddTask(#2/8/2007#, #3/29/2007#, 0.75)
  sf.AddTask(#4/8/2007#, #5/29/2007#, 0.6)
  sf.AddTask(#4/9/2007#, #7/22/2007#, 0.3)
  sf.AddTask(#5/8/2007#, #6/29/2007#, 0.3)
  sf.AddTask(#5/8/2007#, #7/29/2007#, 0.2)
  sf.AddTask(#5/16/2007#, #6/18/2007#, 0)
  sf.AddTask(#6/9/2007#, #6/22/2007#, 0)
  sf.AddTask(#6/1/2007#, #7/15/2007#, 0)
  sf.AddTask(#7/16/2007#, #8/31/2007#, 0)
  sf.AddTask(#7/1/2007#, #8/25/2007#, 0)
  sf.AddTask(#8/8/2007#, #8/29/2007#, 0)
  sf.AddTask(#8/8/2007#, #9/29/2007#, 0)
  sf.AddTask(#8/8/2007#, #9/29/2007#, 0)
  sf.AddTask(#9/8/2007#, #9/29/2007#, 0)
  sf.AddTask(#10/16/2007#, #11/18/2007#, 0)
  With oChart
    .Title = "My test project"
    .Style = STYLE2D3D.STYLE2D_GANTT
    .Series = sf.Series
    .SeriesColor = New Color() {Color.LightYellow}
    .LegendText = "Product development cycle"
    .SeriesLegend = New String() {"V1.0"}
    .DataTableText = "Project tasks"
    .DataTableBackColor = Color.LightGray
    .ItemsLegend = New String() {"Brainstorm 1", "Brainstorm 1", "Q&A 1", "Q&A 2", "Planning", "Design 1", "Design 2", "Acquire materials", "Prepare resources", "Final planning", "Build 1", "Test 1", "Build 2", "Test 2", "Verify results", "Report results", "Deliver package", "Feedback"}
    .ShowXAxis = True ' Show date scale on x-axis
    .ShowDividersX = True
    .XAxisLabelsRotated = True
    .XAxisValuesFont = New Font("Arial", 8)
    .ShowSurface = True
    .ShowValues = False ' No values over bars
    .BorderColor = Color.White ' No border
 
    .GanttSetToday = #6/8/2007#
    .Resolution = 100 ' Default is 72. Increase for better printing quality
   End With
   ' Now, let's output the report sheet...
   Response.Clear()
   Response.ContentType = "Application/pdf"
   ' Get a byte array with the PDF report with a margin of 50 units
   Dim pdf As Byte() = oChart.CreatePDF_ReportSheet(50)
   Response.OutputStream.Write(pdf, 0, pdf.Length)
   ' Free memory
   oChart.Dispose()
End Sub
End Class

Results:

« Last Edit: February 16, 2016, 12:02:27 PM by CrossingCharts »