Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Line Graph

Former Member
0 Kudos

Hi,

I want to create a line graph which will have the x-axis values from an internal table . I tried with FM 'graph_stat' but it is not possible. Can someone please help me?

Regards,

Sharbani

11 REPLIES 11

Aashish28
Contributor
0 Kudos

Hiii sharbani,

                     In se80 see package - SGRB it contains graphics examples you can refer them -  GFW_PROG_COLUMNS_AND_TIME_AXIS.

BR,

Ashish

Former Member
0 Kudos

Hi Ashish,

Thanks for the response. I tried that earlier . But I am not clear with the concepts of OOPs. Is there any way out with other FM??

0 Kudos

Hiii sharbani,

                      If you need FM based graph than you can see - GRBUSGMN , GRBUSG_1 , GRBUSG_M demo example or for more detail search fm in se37 - GRAPH* and than find where to use and see examples you will find many FM based examples.

but personally i would suggest you go with OOPS based approach that is better than this and with oops you have many options and chart/graphs available just try you will succeed in oops based approach also , just think about future proof.

BR,

Ashish

Former Member
0 Kudos

Hi Ashish,

Thank you so much for your response. I want to try with OOPs. Can you please help me a bit more in that. I am too confused with those package and programs. I am unable to understand properly and implement. Can you please help me.

Thanks & Regards,

Sharbani

Former Member
0 Kudos

Hi,

One more thing. Is there any way to create graph in excel directly from the internal table?? If yes then that will be best for me. Please help.

Regards,

Sharbani

matt
Active Contributor
0 Kudos

0 Kudos

Hiii sharbani ,

                      All demo examples which is present in package - SGRB contain simple steps for creating graph on custom container just debug one time you can easily understand flow.

i hope you have knowledge of containers .

and for graph on xls - yes you can do this also , use OLE based approach or you can use ABAP2XLSX.

Thanks ,

Ashish

Former Member
0 Kudos

Hi,

My problem is not yet solved. Please help me, I want a simple line graph in excel which will take values from internal table. The X-axis labels will also be from the internal table, For eg, I want the material wise values. so the x-axis must have the material numbers and y-axis will have the values.

Please help me out.

Regards,

Sharbani

0 Kudos

Hiiii,

        If you are urgent requirement see and modify below OLE2 based code as per your requirement -

Note - please clear and remove unnecessary variables . this is running code

but i would suggest you see and use ABAP2XLSX , if it is not urgent requirement

BR,

Ashish

include ole2incl.
FIELD-SYMBOLS: <FS> .
CONSTANTS: CO_09(2) TYPE N VALUE 09.
data: lv_space(1) type c VALUE '|'.
types: ty_data1(15000) type c,
ty_data TYPE TABLE OF TY_DATA1.
data:GT_OUTPUT TYPE TY_DATA,
wa_output like line of gt_output,
lv_active type i,
lv_inactive type i.

data:GT_OUTPUTv TYPE TY_DATA,
wa_output1 like line of gt_output.

DATA: h_excel TYPE ole2_object, " Excel object
h_mapl TYPE ole2_object, " list of workbooks
worksheet TYPE ole2_object, " list of workbooks
workbook TYPE ole2_object,
range TYPE ole2_object,
h_map TYPE ole2_object,
gs_cell1 TYPE ole2_object,
gs_cell2 TYPE ole2_object,

gs_cell3 TYPE ole2_object,
gs_cell4 TYPE ole2_object,
range1 TYPE ole2_object,


h_chart1 TYPE ole2_object,
ch_title TYPE ole2_object,
ac1 TYPE ole2_object,
ac2 TYPE ole2_object,
ac3 TYPE obj_record,
gs_font TYPE obj_record,
gs_colour TYPE obj_record,
h_chart TYPE ole2_object, " workbook
h_chart2 TYPE ole2_object,
h_chart_obj TYPE ole2_object,
h_chart_shape TYPE ole2_object,
ch_font TYPE ole2_object,
h_chart3 TYPE ole2_object,
file_name type string.
data:
begin of wa,
object_type(50) type c,
count(50) type c,
end of wa,
it_report like standard table of wa.

data: lin1 type i.
ASSIGN lv_space TO <FS> TYPE 'X'.
<FS> = CO_09.
wa-object_type = 'material'.
wa-count = 'count'.
append wa to it_report.
wa-object_type = 'mobile'.
wa-count = '20'.
append wa to it_report.
wa-object_type = 'pda'.
wa-count = '30'.
append wa to it_report.
wa-object_type = 'laptops'.
wa-count = 50.
append wa to it_report.
LOOP AT it_report INTO wa.
CONCATENATE wa-object_type
"wa-count
''
INTO WA_OUTPUT.
*SEPARATED BY lv_space.
APPEND WA_OUTPUT TO GT_OUTPUT.
CLEAR WA_OUTPUT.
endloop.

LOOP AT it_report INTO wa.
CONCATENATE wa-count
''
INTO WA_OUTPUT1.
*SEPARATED BY lv_space.
APPEND WA_OUTPUT1 TO GT_OUTPUTv.
CLEAR WA_OUTPUT1.
endloop.

DATA L_RC TYPE I.
DATA L_RC1 TYPE I.

***************** creates an excel application
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
*Sheet1
CALL METHOD OF h_excel 'Workbooks' = h_mapl.
SET PROPERTY OF h_excel 'Visible' = 1.
*************** opens a work book
CALL METHOD OF h_mapl 'Add' = h_map.
*************** gets the current worksheet
GET PROPERTY OF h_excel 'activesheet' = worksheet.
*************** sets the name of the worksheet
SET PROPERTY OF worksheet 'Name' = 'sheetnew'.
*********** pass data to sheet
CALL METHOD OF worksheet 'Cells' = gs_cell1
EXPORTING
#1 = 1 " starting row of selection
#2 = 1. " starting column of selection
CALL METHOD OF worksheet 'Cells' = gs_cell2
EXPORTING
#1 = 1 " ending row of selection
#2 = 1. " ending column of selection
CALL METHOD OF worksheet 'Range' = range
EXPORTING
#1 = gs_cell1
#2 = gs_cell2.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_EXPORT
IMPORTING
DATA = GT_OUTPUT[]
CHANGING
RC = L_RC.

CALL METHOD OF RANGE 'Select'.
CALL METHOD OF WORKSHEET 'Paste'.

CALL METHOD OF worksheet 'Cells' = gs_cell3
EXPORTING
#1 = 1 " starting row of selection
#2 = 2. " starting column of selection
CALL METHOD OF worksheet 'Cells' = gs_cell4
EXPORTING
#1 = 1 " ending row of selection
#2 = 2. " ending column of selection
CALL METHOD OF worksheet 'Range' = range
EXPORTING
#1 = gs_cell3
#2 = gs_cell4.


CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_EXPORT
IMPORTING
DATA = GT_OUTPUTV[]
CHANGING
RC = L_RC1.

CALL METHOD OF RANGE 'Select'.
CALL METHOD OF WORKSHEET 'Paste'.


**************************************
*************** create a chart sheet
CALL METHOD OF h_excel 'charts' = h_chart.
*************** add a chart of variable h_chart1
*************** opens the initially created sheet
CALL METHOD OF worksheet 'Select'.
CALL METHOD OF h_excel 'Cells' = gs_cell1
EXPORTING
#1 = 1 " starting row of selection
#2 = 1. " starting column of selection
CALL METHOD OF h_excel 'Cells' = gs_cell2
EXPORTING
#1 = 4 " ending row of selection
#2 = 2. " ending column of selection
*************** combine cells to form the range
CALL METHOD OF h_excel 'Range' = range
EXPORTING
#1 = gs_cell1
#2 = gs_cell2.
*************** sets the chart type
CALL METHOD OF h_excel 'charts' = h_chart2.
call method of h_chart2 'add' = h_chart3.
SET PROPERTY OF h_chart3 'charttype' = '69'.
********************************************** title for chart
SET PROPERTY OF h_chart3 'HasTitle' = 1.
GET PROPERTY OF h_chart3 'ChartTitle' = ch_title.
GET PROPERTY OF ch_title 'Characters' = ch_title.
SET PROPERTY OF ch_title 'text' = 'inventory comparison'.
CALL METHOD OF h_chart3 'SetSourceData'
EXPORTING #1 = range " range to be passed to the chart
#2 = 2. " selcts row/column
CALL METHOD OF h_chart3 'ApplyDataLabels'
exporting
#1 = '5'.
****** selects worksheet
CALL METHOD OF worksheet 'Select'.
CALL METHOD OF h_excel 'Cells' = gs_cell1
EXPORTING
#1 = 1 " starting row of selection
#2 = 1. " starting column of selection
CALL METHOD OF h_excel 'Cells' = gs_cell2
EXPORTING
#1 = 1 " ending row of selection
#2 = 2. " ending column of selection
CALL METHOD OF h_excel 'Range' = range
EXPORTING
#1 = gs_cell1
#2 = gs_cell2.
*********** sets the bold for the header
GET PROPERTY OF range 'Font' = GS_FONT .
SET PROPERTY OF GS_FONT 'Bold' = 1 .
free object h_excel.

himanshu_gupta13
Employee
Employee
0 Kudos

Hi,

With help of module function 'GRAPH_MATRIX_3D' you can make any graphs I show below the example code for line graph:

**Simple report to create graph in ABAP
**using GRAPH_MATRIX_3D function module
**The graph shows the performance of 3 companies for the Four
**quarters of a single year
**AUTHOR : HIMANSHU GUPTA
**
**structure declaration for performance measurement
**
TYPES:
BEGIN OF ty_performance,
company(15)
TYPE c,
q1
TYPE i,
q2
TYPE i,
q3
type i,
q4
type i,
END OF ty_performance.

*structure declaration for options table
types : BEGIN OF ty_opttable,
options(30)
TYPE c,
END OF ty_opttable.

*Internal table and work area declarations
DATA: it_performance
TYPE STANDARD TABLE OF ty_performance,
wa_performance
TYPE ty_performance.

DATA : it_opttable type standard table of ty_opttable,
wa_opttable
type ty_opttable.

*initialization event
INITIALIZATION.

*start of selection event
START-OF-SELECTION.

*clearing the work areas
CLEAR WA_PERFORMANCE.
CLEAR wa_opttable.

*appending values into the performance internal table
wa_performance-company =
'Company A'.
wa_performance-q1      =
78.
wa_performance-q2      =
68.
wa_performance-q3      =
79.
wa_performance-q4      =
80.

append wa_performance to it_performance.

wa_performance-company =
'Company B'.
wa_performance-q1      =
48.
wa_performance-q2      =
68.
wa_performance-q3      =
69.
wa_performance-q4      =
70.

append wa_performance to it_performance.

wa_performance-company =
'Company C'.
wa_performance-q1      =
78.
wa_performance-q2      =
48.
wa_performance-q3      =
79.
wa_performance-q4      =
85.

append wa_performance to it_performance.

*appending values into the options internal table
wa_opttable-options =
'P3TYPE = 2D'. "TO'.
APPEND wa_opttable TO it_opttable.

wa_opttable-options =
'P3TYPE = LI'. "TO'.
APPEND wa_opttable TO it_opttable.

wa_opttable-options =
'P2TYPE = LN'. "VB'.
APPEND wa_opttable TO it_opttable.

wa_opttable-options =
'TISIZE = 1'. "1'.
APPEND wa_opttable TO it_opttable.

*calling the graph function module
CALL FUNCTION 'GRAPH_MATRIX_3D'
EXPORTING
col1      =
'Quarter 1'
col2      =
'Quarter 2'
col3      =
'Quarter 3'
col4      =
'Quarter 4'
dim1      =
'In Percentage%'
set_focus =
'X'
titl      =
'Company Performances'
TABLES
data      = it_performance
opts      = it_opttable
EXCEPTIONS
others    = 1.

Output  is:


NOTE: here you have to assign the options according to the required type of graph:

      wa_opttable-options = 'TISIZE = 1'. "1'.
     
APPEND wa_opttable TO it_opttable.

Many Thanks / Himanshu Gupta

0 Kudos

Hi Himanshu,

Thanks for the response. But here also you are entering the values of the X-axis like quarter1,quarter2 etc. I want those values from the internal table itself. Like my case is that I want material no. values from internal table in the X-axis and the no. of divisions will also be dynamic. Please help me.

Regards,

Sharbani