cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
pmroz
Super User

Refresh Graph in Dialog Box

I'm displaying a radio box and a graph in a "new window".  If the user selects a different graph in the radio box I want the old graph deleted and the new graph displayed, all in the same window.  Not sure how exactly to do this.  Here's a simple example that displays the first chart. 

dt = open("$sample_data\Big Class.jmp");

my_1_script = expr(

    my_gb = Graph Builder(

        Show Control Panel( 0 ),

        Variables( X( :weight ), Y( :height ) ),

        Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 3 ) ) )

    );

);

my_2_script = expr(

    my_gb = Graph Builder(

        Show Control Panel( 0 ),

        Variables( X( :sex ), Y( :age ) ),

        Elements( Histogram( X, Y, Legend( 5 ) ) )

    );

);

my_3_script = expr(

    my_gb = Graph Builder(

        Show Control Panel( 0 ),

        Variables( X( :age ), Y( :age ) ),

        Elements(

            Pie( X, Y, Legend( 2 ), Pie Style( "Pie" ),

                Summary Statistic( "Mean" ), Label( "No Labels" )

            )

        )

    );

);

chart_list = {"Chart 1", "Chart 2", "Chart 3"};

//------------------------------------------------------------------------------

my_win = new window("Chart Display",

    panelbox("Graph Options",

        hlistbox(

            panelbox("Select Chart",

                chart_rb = radiobox(chart_list,

                    selected_chart = chart_rb << get selected;

                    if (selected_chart == "Chart 1",

                        my_1_script,   

                        selected_chart == "Chart 2",

                        my_2_script,

                        selected_chart == "Chart 3",

                        my_3_script

                    )

                )

            ),

        )

    ),

// Default is chart 1

    my_1_script

);

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Refresh Graph in Dialog Box

If given a variable name, the graph can easily be deleted before appending the graph to the window.

This seems to work:

my_win = New Window( "Chart Display",

      Panel Box( "Graph Options",

            H List Box(

                  Panel Box( "Select Chart",

                        chart_rb = Radio Box(

                              chart_list,

                              selected_chart = chart_rb << get selected;

                              If(selected_chart == "Chart 1",

                                          gb << delete;

                                          my_win << append( gb = my_1_script ),

                                    selected_chart == "Chart 2",

                                          gb << delete;

                                          my_win << append( gb = my_2_script ),

                                    selected_chart == "Chart 3",

                                          gb << delete;

                                          my_win << append( gb = my_3_script ),

                              );

                        )

                  ),

            )

      ),

// Default is chart 1

      gb = my_1_script

);

View solution in original post

3 REPLIES 3
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Refresh Graph in Dialog Box

If given a variable name, the graph can easily be deleted before appending the graph to the window.

This seems to work:

my_win = New Window( "Chart Display",

      Panel Box( "Graph Options",

            H List Box(

                  Panel Box( "Select Chart",

                        chart_rb = Radio Box(

                              chart_list,

                              selected_chart = chart_rb << get selected;

                              If(selected_chart == "Chart 1",

                                          gb << delete;

                                          my_win << append( gb = my_1_script ),

                                    selected_chart == "Chart 2",

                                          gb << delete;

                                          my_win << append( gb = my_2_script ),

                                    selected_chart == "Chart 3",

                                          gb << delete;

                                          my_win << append( gb = my_3_script ),

                              );

                        )

                  ),

            )

      ),

// Default is chart 1

      gb = my_1_script

);

pmroz
Super User

Re: Refresh Graph in Dialog Box

Truly awesome MS.  I knew it was relatively simple but couldn't quite get the syntax right.  Thanks!

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Refresh Graph in Dialog Box

This is a simpler version using the same approach that may be easier to generalize:

chart_list = {"Chart 1", "Chart 2", "Chart 3"};

script_list = {my_1_script, my_2_script, my_3_script};

my_win = New Window( "Chart Display",

      Panel Box( "Graph Options",

            H List Box(

                  Panel Box( "Select Chart",

                        chart_rb = Radio Box(

                              chart_list,

                              gb << delete;

                              my_win << append( gb = Eval( script_list[chart_rb << get] ) )

                        ),

                  )

            )

      ),

// Default is chart 1

      gb = eval(script_list[1])

);