Subscribe Bookmark RSS Feed

Problem using Graph Builder with Data Filter

martaruth0

New Contributor

Joined:

Jun 16, 2016

Graph Builder works succussfully with the Data Filter adjusteing the plotted points properly when the Data Filter slider is moved. Also, the values of the statistics using the Caption Box adjust with the Data Filter slider as expected. So far, so good. Then I wanted to plot the mean of a column using 'Customize' and 'Y Function'. The following is the extracted script:

Add Graphics Script(

  3,

  Description( "Script" ),

  Y Function( Col Mean( :_columnexample_ ), x )

  )

The desired mean line is plotted successsfully. However, the plotted line is unresponsive to the Data Filter slider.

How can I plot the column mean that works with the Data Filter?

4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

The solution will probably be dependent upon whether you are using a Data Filter, or a Local Data Filter.  If you are using a Data Filter, you can apply a Row State Handler to the data table, that will redraw the Y Function.  If it is a Local Data Filter, the key will be in finding what is changed in the graph by the filter that one can trigger on, to redraw the Y Function.

If you can provide more details on the Data Filter you are using, I might be able to provide more of a solution

Jim
martaruth0

New Contributor

Joined:

Jun 16, 2016

Thanks for the response.

Here's the script for the data filter, it's not local:

Current Data Table() << Data Filter(

Location( {325, 212} ),

Mode( Show( 1 ), Include( 1 ) ),

Add Filter( columns( :Bandmeter ), Where( :Bandmeter >= -100 & :Bandmeter <= -50 ) )

);?

I'm guessing the problem lies with the Include(1) statement, perhaps it should be Exclude. My 30 day free trial just ended, so I'll have to wait to get a license to test it.

Some arbitrary initial values for the filter are included simply because I haven't figured out yet how to include all the rows of the current data table. It seemed to be a lesser issue at the moment, but I'm also presuming that it is not the cause for the difficulty in the use of the Data Filter with the Y Function.

ian_jmp

Staff

Joined:

Jun 23, 2011

Building on Jim's thought, here's one way (with the local data filter):

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Graph Builder

gb = dt << Graph Builder(

Show Control Panel( 0 ),

Lock Scales( 1 ),

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

Elements( Points( X, Y, Legend( 6 ) ), Line Of Fit( X, Y, Legend( 8 ) ) ),

);

// Get a reference to the report

gbReport = gb << Report;

// Add a local data filter

ldf = gb << Local Data Filter( Add Filter( columns( :sex ) ) );

// Row state handler function that adds a horizontal line to Graph Builder at the mean of the current

// selection in the local data filter

addMeanYLine =

Function({x}, {Default Local},

// Get rows corresponding to the current selection

rows = ldf << getFilteredRows;

// Get the required mean value

mv = Mean((Column(dt, "height") << getValues)[rows]);

// Add the graphics script to the Graph Builder display box . . .

gFrames = gbReport << XPath( "//FrameBox" );

// Try to remove a graphics script that might already be there

Try(Send(gFrames[1], RemoveGraphicsScript(1)));

// Expression that will add the required graphics script

ags = Expr(Send(gFrames[1], AddGraphicsScript(PenColor("Red"); HLine(TBD))));

// 'Bake in' current mean value

SubstituteInto(ags, Expr(TBD), mv);

// Add the graphics script

ags;

);

// Assign the row state handler to the local data filter display box

rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(addMeanYLine);

martaruth0

New Contributor

Joined:

Jun 16, 2016

Thank you Ian for answering. I have studied your script and see that it works. In my case, however, I need to keep the data filter global so that many graphs can be affected at once, and I haven't yet managed this.