For creating charts and diagrams the .NET class System.Windows.Forms.DataVisualization.Chart can be used.

We use this class to integrate a diagram "orders" into transaction VD03 (Display Customer), Sales Area Data:

 

The implementation consists of the steps below:

  • Insert a pushbutton for displaying the diagram, display the image file.

  • Read the order data

  • Create the diagram as an image file

 

For the first part a few lines of code are sufficient:

// Reset variables if new transaction or new customer
if not V[VD03_transactionid=&V[_transactionid]]
 
or not
V[VD03_kunnr=&F[RF02D-KUNNR]]

  Set V[VD03_*] ""
  Set V[VD03_transactionid] "&V[_transactionid]"
  Set V[VD03_kunnr] "&F[RF02D-KUNNR]"

endif

if Q[transaction=VD03] and Q[Page=Verkauf]
 
Set V[chartfilename] "&%[TEMP]\saleschart.&V[VD03_kunnr].png"

  // display chart?
    if V[VD03_display_chart=X]
      Box (7,86) (22,135) "Orders &V[year4] - &V[year0] in thousands"
 
Pushbutton (7,137) "x" size=(1,1) process="chart_close.txt"
     Image (8,87) "&V[chartfilename]" -noBuffer

  else
      Pushbutton (7,86) "@NF\QDisplay chart@Chart orders" process="chart_open.txt"
  endif
endif

 

InputScript "chart_open.txt":

// Generate chart

...

// Display chart
Set V[VD03_display_chart] "X"
Return

 

InputScript "chart_close.txt":

// Close chart
Set V[VD03_display_chart] ""
Return

 

The user can call up the diagram by pushing a button and can also close it afterwards:

 



 

In order to read the data for the diagram we will use our function module /guixt/select.
We read one of the statistic tables of the sales information system (VIS); either the SAP standard table S001 or, due to performance reasons, a copy of S001 where the key for the material number is removed. Then we call the VB.NET function to create the diagram:

// Determine years
Set
V[year0] &V[today_y]
Set V[year1] &V[year0] - 1
Set V[year2] &V[year0] - 2
Set V[year3] &V[year0] - 3
Set V[year4] &V[year0] - 4

// ialize sales figues
Set V[sales0] 0
Set V[sales1] 0
Set V[sales2] 0
Set V[sales3] 0
Set V[sales4] 0

// key values
Set V[kunnr] "&F[RF02D-KUNNR]"
Set V[vkorg] "&F[RF02D-VKORG]"
Set V[vtweg] "&F[RF02D-VTWEG]"
Set V[spart] "&F[RF02D-SPART]"

// leading zeros
Set V[kunnr](1-10) "0000000000&V[kunnr]" -alignRight

// search condition
Set V[condition] "KUNNR = '&V[kunnr]' and VKORG = '&V[vkorg]' and VTWEG = '&V[vtweg]' and SPART = '&V[spart]' and SPMON GE '&V[year4]01'"

// read VIS statistics table S001
Call /guixt/select in.table="S951" in.Condition="&V[condition]" in.Fields="SPMON,AENETWR" table.V1table="r1" table.V2table="r2"

// Build sales figures
Set V[i] 1
label next
CopyText fromText="r1" toString="spmon" line="&V[i]"

if Q[ok]
  CopyText fromText="r2" toString="aenetwr" line="&V[i]"
     Set V[i] &V[i] + 1
   
Set V[year] &V[spmon](1-4)

  // year0
  if V[year=&V[year0]]
        Set V[sales0] &V[sales0] + &V[aenetwr]
        goto next
   
endif

  // year1
  if V[year=&V[year1]]
        Set V[sales1] &V[sales1] + &V[aenetwr]
        goto next
   
endif

  // year2
  if V[year=&V[year2]]
        Set V[sales2] &V[sales2] + &V[aenetwr]
        goto next
   
endif

  // year3
  if V[year=&V[year3]]
        Set V[sales3] &V[sales3] + &V[aenetwr]
        goto next
   
endif

  // year4
  if V[year=&V[year4]]
        Set V[sales4] &V[sales4] + &V[aenetwr]
        goto next
   
endif

   goto next

endif

 

// in thousands

Set V[sales0] &V[sales0] / 1000 decimals=0
Set V[sales1] &V[sales1] / 1000 decimals=0
Set V[sales2] &V[sales2] / 1000 decimals=0
Set V[sales3] &V[sales3] / 1000 decimals=0
Set V[sales4] &V[sales4] / 1000 decimals=0

// generate chart
CallVB Chart01.Customer.SalesChart &quo"&V[chartfilename]"

We pass the name of the image file to be created to the VB.NET function:
The required data for the diagram (orders and years) can be taken directly from the GuiXT variables:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms.DataVisualization.Charting


Public Class customer

    Private guixt As New guinet.guixt

    Public Sub SalesChart(ByVal imgfilename As String)

        ' create chart
        Dim Chart1 As New Chart()

        Chart1.Size = New System.Drawing.Size(480, 340)
        Chart1.BackColor = Color.DeepSkyBlue

        Dim ChartArea1 As New ChartArea

        ChartArea1.Name = "ChartArea1"
        Chart1.ChartAreas.Add(ChartArea1)

        Dim Series1 As New Series
        Series1.ChartArea = "ChartArea1"
        Series1.Palette = ChartColorPalette.Pastel
        Series1.XValueMember = "Year"
        Series1.YValueMembers = "Sales"
        Chart1.Series.Add(Series1)

        Dim table As New DataTable

        ' Create columns in the DataTable
        table.Columns.Add("Year", GetType(String))
        table.Columns.Add("Sales", GetType(Integer))

        ' Add sales figures for 5 years, using GuiXT variables
        table.Rows.Add(guixt.GetVariable("year4"), _ 
			CInt(guixt.GetVariable("sales4")))

        table.Rows.Add(guixt.GetVariable("year3"), _
			CInt(guixt.GetVariable("sales3")))

        table.Rows.Add(guixt.GetVariable("year2"), _ 
			CInt(guixt.GetVariable("sales2")))

        table.Rows.Add(guixt.GetVariable("year1"), _ 
			CInt(guixt.GetVariable("sales1")))

        table.Rows.Add(guixt.GetVariable("year0"), _ 
			CInt(guixt.GetVariable("sales0")))

        ' Chart data
        Chart1.DataSource = table

        ' save chart as .png file
        Chart1.SaveImage(imgfilename, ChartImageFormat.Png)

    End Sub
End Class