Skip to Content
author's profile photo Former Member
Former Member

Line Graph

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on May 25, 2013 at 12:16 PM

    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


    graph.JPG (66.2 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Posted on May 25, 2013 at 11:09 AM

    Hiii sharbani,

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

    BR,

    Ashish

    Add a comment
    10|10000 characters needed characters exceeded

    • 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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.