[ABAP] Einfache Charts anzeigen mit cl_time_chart_simple

* Kapselt: cl_gui_chart_engine
* Demo: RSORA_TCS_DEMO
* Vorteil: einfache Handhabung
* Nachteil: nur eingeschränktes Chart-Customizing (Einstellungen)
CONSTANTS: co_graph_id TYPE tcs_graph_id VALUE 'S_GRAPH1'.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_click FOR EVENT click OF cl_time_chart_simple
        IMPORTING
            element
            series_nr
            point_nr
            clicked_entry
            clicked_series
            sender.
    CLASS-METHODS:
      on_property_change FOR EVENT property_change OF cl_time_chart_simple
        IMPORTING
            element
            name
            value
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.

  METHOD on_click.
    MESSAGE |{ element } { series_nr } { point_nr } { clicked_entry-yvalue } { clicked_series }| TYPE 'S'.
  ENDMETHOD.

  METHOD on_property_change.
    MESSAGE |{ element } { name } { value }| TYPE 'S'.
  ENDMETHOD.

ENDCLASS.

* Dummy-Screen für cl_gui_container=>default_screen deklarieren
SELECTION-SCREEN BEGIN OF SCREEN 100.
SELECTION-SCREEN END OF SCREEN 100.

START-OF-SELECTION.
  TRY.
      DATA(o_tcs) = NEW cl_time_chart_simple( i_container = cl_gui_container=>default_screen ).

* Customizing, leider nur vier Parameter einstellbar
* erweitertes Customizing nur über die Methoden load_customizing... möglich (s.u.)
      DATA(lv_cust) = VALUE tcs_s_customizing( charttype  = 'TimeScatter'
                                               charttitle = 'Time Chart Simple Demo'
                                               yaxistext  = 'Höhe'
                                               yaxisunit  = '[mm]'
                                             ).

      o_tcs->set_customizing( lv_cust ).

* Daten
      DATA(it_data) = VALUE tcs_t_data( ( series    = 'Series 1'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '100000' i_milli = '000' )
                                          yvalue    = '1.2'
                                        )
                                        ( series    = 'Series 1'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '110000' i_milli = '100' )
                                          yvalue    = '1.5'
                                        )
                                        ( series    = 'Series 1'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '120000' i_milli = '200' )
                                          yvalue    = '1.9'
                                        )

                                        ( series    = 'Series 2'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '100000' i_milli = '500' )
                                          yvalue    = '1.0'
                                        )
                                        ( series    = 'Series 2'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '110000' i_milli = '700' )
                                          yvalue    = '1.2'
                                        )
                                        ( series    = 'Series 2'
                                          timestamp = cl_time_chart_simple=>create_timestamp( i_date  = '20190101' i_time  = '120000' i_milli = '800' )
                                          yvalue    = '1.6'
                                        )
                                      ).

      o_tcs->set_data( it_data ).

* Events
      SET HANDLER lcl_events=>on_click FOR o_tcs.
      SET HANDLER lcl_events=>on_property_change FOR o_tcs.

* Einstellungen anzeigen
      o_tcs->toggle_customizing_mode( ).

** interessante Funktionen (sollten durch Buttons getriggert werden):
** Drucken
*  o_tcs->print_chart( ).
** Grafik speichern
*  o_tcs->save_chart( ).
** Filter
*  o_tcs->filter_data_top_n( 3 ).
*  o_tcs->filter_data_top_n( 0 ).
** Zoom
*  o_tcs->zoom_in( 40 ).
*  o_tcs->zoom_out( 40 ).
** Scroll
*  o_tcs->scroll_left_border(  ).
*  o_tcs->scroll_left( 100 ).
*  o_tcs->scroll_left( 25 ).
*  o_tcs->scroll_right( 25 ).
*  o_tcs->scroll_right( 100 ).
*  o_tcs->scroll_right_border( ).
** Customizing als Datei laden/speichern
*  o_tcs->load_customizing_frontend( ).
*  o_tcs->save_customizing_frontend( ).
** Customizing auf DB laden/speichern/löschen
*  o_tcs->load_customizing_db( co_graph_id ).
*  o_tcs->save_customizing_db( co_graph_id ).
*  o_tcs->delete_customizing_db( co_graph_id ).

* cl_gui_container=>default_screen erzwingen
      CALL SCREEN 100.

    CATCH cx_root INTO DATA(e_text).
      WRITE: / e_text->get_text( ).
  ENDTRY.