Graph Builder: hide X categories with no dataHello everyone,
I have a table with a grouping column and several response variables.
New Table( "Test",
Add Rows( 7 ),
New Column( "GROUP",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d", "e", "f", "g"} )
),
New Column( "Y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [7, ., 6, ., 4, ., 2] )
),
New Column( "Y 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [7, 6, 2, 3, ., ., .] ),
Set Display Width( 49 )
)
)I would like to create a bar chart with a column switcher.
Graph Builder(
Size( 527, 448 ),
Show Control Panel( 0 ),
Variables(
X( :GROUP, Order By( :Y, Ascending, Order Statistic( "Mean" ) ) ),
Y( :Y )
),
Elements( Bar( X, Y, Legend( 4 ) ) ),
Column Switcher( :Y, {:Y, :Y 2} )
)My problem is that I do not want to display levels with no data. In other words, I do not want to see levels "b", "d" and "f" for Y and levels "e", "f", "g" for Y2.

I tried to use a "where" clause but unfortunately it is not taken into acount by the Column Switcher.
Do you have any idea of how we could do that?
Thanks in advance!
Re: Graph Builder: hide X categories with no dataHi @geoffrey_mann ,
Thank you for your involvement and the additional informations.
I will start advertising the feature to my colleagues to get votes! 
Regarding the script, I prefer not affecting the current table so I think the local data filter is a good option! I will explore this possibility deeper.
Re: Graph Builder: hide X categories with no dataHi @anne_sa
I'm so glad this helped. It is something I have wanted to do for a while and you gave me the motivation. 
Also, I agree with you and @vince_faller that a listener or a way to custom behavior around column switcher would be generally useful to those programming their own addins or changing behavior. We do this all of the time in JMP Clinical and JMP Genomics, which is why I gave credit to @kelci_miclaus and @drewfoglia for the code I borrowed.
If only we knew a JMP product manager who could help make this happen.
Please both of you vote for the feature and it will help with the justification.
As to the final changes, you should have control in your wrapper code you wrote. The API calls are simply meant to replace the X and Y variables. I will keep adding to these functions to help programmers simplify wrapping GraphBuilder so that they may build addins faster. What I am trying to say here is only add functios to update GraphBuilder in the API file so that any "driver" file you use has the selection behavior. Note that I could have put the dt << clearrowstates(); call below the ReplaceGB... calls to organize the changing of row states to the table in one place. Also note that this code is modifying the row states of the main data table instead of using a local filter to modify the GraphBuilder report. You may want to change your approach if you want multiple reports of the data table. But these are just notes and intended as extra information for the future apps you may build with JMP.
Notice the clearrowstates in your driver file:
dt << clearrowstates();
newvarname = lb<<GETSELECTED></GETSELECTED>
Based on my "simplistic" understanding of what you are trying to do I recommend you simply replace dt << clearrowstates(); with dt << unexclude(); Let me know if that is the behavior that you prefer or if it is more complex than that.
Re: Graph Builder: hide X categories with no data I totally agree with you @vince_faller, it would be a very nice feature 
I think I will add it to the JMP Wish List!
Re: Graph Builder: hide X categories with no dataThank you very much for these scripts @geoffrey_mann
It is definitely cleaner than what I did!
There is just one thing that I would like to adapt: each time we select a new variable in the list box, the row status are reset. Thus if some points have been labelled / excluded / colored... we will loose this information and it can be annoying.
Otherwise it matches my expectations so thanks again!
Re: Graph Builder: hide X categories with no dataIt'd be cool if column switch has a <Re: Graph Builder: hide X categories with no data
Hi again @anne_sa ,
Sorry for the delay, I actually caught the flu for a few days and got behind a little.
I have attached two files. The first jsl file (Example Script for Changing row states.jsl) is the driver file and the path in the second line is the full path of the location that you place the second file (GraphBuilderJSLAPI.jsl).
//Include script to modify GraphBuilder with some special functions defined
include(ConvertFilePath("/Users/gemann/Projects/Prototypes/JSLClasses/GraphBuilderJSLAPI.jsl", absolute, windows));
//Create a sample table
dt = New Table( "Test",
Add Rows( 7 ),
New Column( "GROUP",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d", "e", "f", "g"} )
),
New Column( "Y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [7, ., 6, ., 4, ., 2] )
),
New Column( "Y 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [7, 6, 2, 3, ., ., .] ),
Set Display Width( 49 )
)
);
//Add a new window and build a listbox beside a graphbuilder
New Window( "CustomColumnSwitcher Window",
//Start by getting all of the columns in the current datatable
CNames = dt << Get Column Names( Numeric );
Show( CNames );
//User a horizontal layout
HListBox(
//Use a ListBox as the new Column Switcher
lb = List Box(
CNames,
maxSelected(1),
//The next lines specify the script that gets run when an item in listbox is selected
dt << clearrowstates();
newvarname = lb<<GETSELECTED></GETSELECTED>
Good luck and let me know if you have any issues. Of course these files are not fully tested!!! 
Re: Graph Builder: hide X categories with no dataHi @geoffrey_mann ,
I have written something to basically update the column switcher and change the axis setting (as suggested by @julian ) each time we select a new variable. However it may not be very efficient so of course I am very interested by your solution!
Re: Graph Builder: hide X categories with no dataHi Anne,
I wanted to check back with you to see if you have found a coding solution to your problem. It took me a while to find the time but I have a coding solution if you still need one.
Re: Graph Builder: hide X categories with no dataHi @julian!
I really appreciate your efforts to solve my problem! Unfortunately, the number of non-missing levels can be different from one response variable to the next one. However, your last post can definitely be used for the “coding solution”. Changing the axis settings based on the level number is indeed a nice way to display what is expected. I will work in that direction. Thanks for your help!
Re: Graph Builder: hide X categories with no dataHi @anne_sa,
I see just what you mean. It really might come down to coding up something custom, but let me take one more interactive stab at this. Are there always only four levels (albeit different levels) of Group for each Y? If so, here's a potential hack: Graph Builder will maintain the X axis upon column switching, and since you have your levels ordered ascending (thus blank levels are always at the end), we could adjust the axis so that only four levels are showing. You can do this in the axis settings (right click the axis > axis settings), or just by dragging out the end of the axis until the missing levels are hidden).
Graph Builder(
Show Control Panel( 0 ),
Variables( X( :GROUP, Order By( :Y, Ascending, Order Statistic( "Mean" ) ) ), Y( :Y ) ),
Elements( Bar( X, Y, Legend( 4 ) ) ),
Column Switcher( :Y, {:Y, :Y 2} ),
SendToReport( Dispatch( {}, "GROUP", ScaleBox, {Min( -0.5 ), Max( 3.5 ), Inc( 1 ), Minor Ticks( 0 )} ) )
);

Maybe a potential solution in your case?
@julian
Re: Graph Builder: hide X categories with no dataThanks @julian for this suggestion! Indeed it allows to display only levels with data.
The only problem (but maybe I ask too much) is that we lose the link between rows. For instance if I select the level "a" for Y and if I want to see the corresponding value for Y2, nothing is highlighted when I select Y2 with the local data filter.
Maybe coding the expected behavior is the solution...
Re: Graph Builder: hide X categories with no dataHi @anne_sa ,
As you discovered, Graph Builder observes those categories of your grouping variable and really will insist on plotting them (which is usually a good thing) since it assumes you find value in them since you kept them in your table. In your case with the column switcher, it's not as simple as just deleting those rows since for your other column data do exist. One solution is restructuring your data so that those missing rows can be eliminated. I would do this by stacking:
Tables > Stack
Data Table( "Test" ) << Stack(
columns( :Y, :Y 2 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
This will return a table like below:

Remove the missing values by right-clicking any of the cells that are missing > select matching. Then, delete those rows. This returns the attached table. Now, make your graph but use a local data filter rather than a column switcher to select what previously was a response from your Label Column:
Graph Builder(
Show Control Panel( 0 ),
Variables( X( :GROUP ), Y( :Data ) ),
Elements( Bar( X, Y, Legend( 4 ) ) ),
Local Data Filter(
Add Filter(
columns( :Label ),
Where( :Label == "Y" ),
Display( :Label, Size( 160, 17 ) )
)
)
);

Since there are no missing rows, Graph Builder displays only those levels of Group that are populated with data. You can, of course, generalize this to any number of levels of Y -- simply stack all of them in the initial step.
I hope this helps!
@julian
Re: Graph Builder: hide X categories with no dataHi Anne,
I see your problem now and am still taking a look at it. I believe this one will take a little coding.Re: Graph Builder: hide X categories with no dataThanks for your answer @geoffrey_mann
Unfortunately is it not exactly what I would like to get because when I select a new column with the column switcher, the local data filter is still based on Y.
Of course it is possible to manually change the local data filter but since I can have a quite high number of variables, it would be great to have an automatic way to do that 
Re: Graph Builder: hide X categories with no dataHi Anne,
Your idea that you need a "where" clause or rather a filter of some sort is correct. Try adding the following line to your graphbuilder script:
Local Data Filter( Add Filter( columns( :Y ), Where( :Y >= 2 & :Y <= 7 ) ) )
I am hoping that a Local Data Filter is okay?
Graph Builder(
Size( 527, 448 ),
Show Control Panel( 0 ),
Variables(
X( :GROUP, Order By( :Y, Ascending, Order Statistic( "Mean" ) ) ),
Y( :Y )
),
Elements( Bar( X, Y, Legend( 4 ) ) ),
Column Switcher( :Y, {:Y, :Y 2} ),
Local Data Filter( Add Filter( columns( :Y ), Where( :Y >= 2 & :Y <= 7 ) ) )
);
Re: Graph Builder: hide X categories with no dataIt is an older post but still this might addd some help:
you may use in addition a local data filter with select missing and inverse for the respective Y.
Local Data Filter(
Inverse( 1 ),
Add Filter( columns( :Y1, :Y2 ), Select Missing( :Y2 ) )
),
Column Switcher( :Y2, {:Y1, :Y2, :Y3} )
You could in addition add an event for the event when selecting another level of the column switcher, which then changes the local data switcher filter setting for all your Y variables of interest. Might be overengineered, but could work.
Re: Graph Builder: hide X categories with no dataHi @martindemel ,
Thanks for your message. Although it's quite an old post it's always great to dsicover different ways to reach the same objective.