Home > Examples, Implementation, Report Scripting > Unbound Report with Scripts

Unbound Report with Scripts

May 10, 2012

Here is an example of what you can do with scripts in a report.   First start with a blank report design with no data source.    Drag a chart object onto the design surface as shown in the figure.

Next add the following code in the scripts tab….

'Define a class to represent an individual record with properties to be data source fields
Public Class Record
  Dim _id As Integer
  Dim _txt As String
  Dim _num as double
  Public Sub New(ByVal id As Integer, ByVal txt As String, ByVal num As Double)
    Me._id = id
    Me._txt = txt
    Me._num = num
  End Sub
  Public Property ID() As Integer
          Return _id
       End Get
       Set(ByVal Value As Integer)
          _id = Value
       End Set
   End Property
   Public Property Txt() As String
          Return _txt
       End Get
       Set(ByVal Value As String)
          _txt = Value
       End Set
    End Property
   Public Property Num() As Integer
          Return _num
       End Get
       Set(ByVal Value As Integer)
          _num = Value
       End Set
    End Property
 End Class

'Populate the chart before printing Private Sub chart1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
     ' Create a list.
     Dim listDataSource As New ArrayList()
    ' Populate the list with records.
     listDataSource.Add(New Record(1, "Android", 29))
     listDataSource.Add(New Record(2, "Galaxy", 32))
     listDataSource.Add(New Record(3, "Lumia", 51))
     listDataSource.Add(New Record(4, "iPhone", 84))
    ' Remove the default series if any
     for i as integer = 0 to chart1.series.count-1
       dim serie as series = chart1.series(i)
     next i
     ' Bind the chart to the list.
     chart1.DataSource = listDataSource
    ' Create a series, and add it to the chart.
     Dim series1 As New Series("My Series", ViewType.Bar)
    ' Adjust the series data members.
     series1.ArgumentDataMember = "txt"
     series1.ValueDataMembers.AddRange(New String() { "num" })
    ' Access the view-type-specific options of the series.
     CType(series1.View, BarSeriesView).ColorEach = True 
     series1.LegendPointOptions.Pattern = "{A}"
End Sub

Now preview the report and you will  get the following:

Sample Report available HERE to download.