This tutorial will show you how to create a report to show sales by AR Sales Area in a graph.
Alt+Q). Between :FromPeriod and :ToPeriod
Alt+C). This will add add the :FromPeriod and :ToPeriod parameters to the Results tab.Alt+C) to check the query for errors. If no errors are found, click F9).F9). The Wizard will generate a report listing all the results of the query. F3):' See AfterQuery code for code relating to the graph
Dim tblGraph as Object
' Create a list of colours to be used in the graph
Dim ColorsForGraph as Object
ColorsForGraph = CreateObject("Accredo.StringList")
ColorsForGraph.CommaText = "red,blue,green,yellow,cyan,pink,silver,brown,purple,teal"
If not Query.IsEmpty then
'Clone the report query and pivot to create the memory table for the bar graph
tblGraph = PivotTable(CloneQuery,"PeriodID;PeriodName","SalesAreaCode","Sum(PeriodActivity)",False)
graphBar.Table = tblGraph
graphBar.XDataFieldName = "PeriodID"
graphBar.XLabelFieldName = "PeriodName"
'Dynamically add the graph fields based on the pivot table
TotalFields = tblGraph.Fields.Count
graphPie.ClearAllFields
For x = 0 to TotalFields - 1
tblGraph.Fields.Item(x).DisplayLabel = Replace(tblGraph.Fields.Item(x).DisplayLabel, " PeriodActivity", "")
If x > 1 then
graphField = graphBar.AddField(tblGraph.Fields.Item(x).FieldName)
graphField.DisplayLabel = tblGraph.Fields.Item(x).DisplayLabel
graphField.BrushColor = ColorByName(ColorsForGraph[(X-2) Mod ColorsForGraph.Count])
End If
Next x
'Clone the report query to create the memory table for the pie graph
Dim SQL as String
SQL = "SELECT ARAREA.SalesAreaCode " & _
" ,Min(ARAREA.SalesAreaName) as SalesAreaName " & _
" ,Sum(ARAREBAL.PeriodActivity) as Activity " & _
"FROM ARAREA " & _
" INNER JOIN ARAREBAL ON ARAREA.SalesAreaCode=ARAREBAL.SalesAreaCode " & _
"WHERE ARAREBAL.PeriodID Between :FromPeriod and :ToPeriod " & _
"Group By ARAREA.SalesAreaCode " & _
"ORDER BY Activity desc "
Dim tblgraphBar as Object
tblgraph1 = ExecuteSQL(SQL,FromPeriod,ToPeriod)
'BrowseDataset(tblgraphBar)
graphPie.Table = tblgraph1
graphPie.XDataFieldName = "SalesAreaCode"
graphPie.XLabelFieldName = "SalesAreaName"
graphPie.AddField("Activity")
graphPie.AddPieColor(ColorByName("Orange"))
graphPie.AddPieColor(ColorByName("Blue"))
graphPie.AddPieColor(ColorByName("Green"))
graphPie.AddPieColor(ColorByName("Red"))
graphPie.AddPieColor(ColorByName("Yellow"))
graphPie.AddPieColor(ColorByName("Black"))
graphPie.AddPieColor(ColorByName("Brown"))
'graphPie.ResetPieColors
End If
Ctrl+R) to run the report.