In my case I have dedicated modal window for graph. Each time I press ALV toolbar button I want to see related graph to the grid. I have always prepared an internal table with correct graph data (see below t_graph within the coding).
Screen call e.g.
PBO
MODULE status_0500 OUTPUT.
SET PF-STATUS 'DEFAULT_STATUS'.
SET TITLEBAR 'GRAPH'.
lcl_main=>self->generate_graph( ).
ENDMODULE.
PAI
MODULE exit_command_0500 INPUT.LEAVE TO SCREEN 0. " Back to main screen
ENDMODULE.
The PBO method
The globals
DATA:
go_ce_container TYPE REF TO cl_gui_container.
go_ce_viewer TYPE REF TO cl_gui_chart_engine.
The generator method coding
The whole question is what should be setup each screen call (local variables) and what should remain in memory (global ones). The local class lo_graph is just my rewrite of two performs/subroutines from the demo program GRAPHICS_GUI_CE_DEMO. It's methods are responsible for filling the XML data.
DATA:
lo_graph TYPE REF TO lcl_graph, " custom class preparing XML data for graph
lo_ixml_data_doc TYPE REF TO if_ixml_document,
lo_ixml_custom_doc TYPE REF TO if_ixml_document,
lo_ixml TYPE REF TO if_ixml,
lo_ixml_sf TYPE REF TO if_ixml_stream_factory,
lo_ostream TYPE REF TO if_ixml_ostream,
lv_xstr TYPE xstring.
IF go_ce_container IS INITIAL.
go_ce_container = generate_graph_container( ).
CREATE OBJECT go_ce_viewer
EXPORTING
parent = go_ce_container.
ENDIF.
lo_ixml = cl_ixml=>create( ).
lo_ixml_sf = lo_ixml->create_stream_factory( ).
CREATE OBJECT lo_graph.
lo_graph->create_data(
EXPORTING
it_graph = t_graph
iv_ixml = lo_ixml
CHANGING
cv_ixml_doc = lo_ixml_data_doc
).
lo_ostream = lo_ixml_sf->create_ostream_xstring( lv_xstr ).
lo_ixml_data_doc->render( ostream = lo_ostream ).
go_ce_viewer->set_data( xdata = lv_xstr ).
CLEAR lv_xstr.
lo_graph->create_custom(
EXPORTING
iv_title = v_grid_title
iv_ixml = lo_ixml
CHANGING
cv_ixml_doc = lo_ixml_custom_doc
).
lo_ostream = lo_ixml_sf->create_ostream_xstring( lv_xstr ).
lo_ixml_custom_doc->render( ostream = lo_ostream ).
go_ce_viewer->set_customizing( xdata = lv_xstr ).
go_ce_viewer->render( ).
ENDMETHOD. "generate_graph