cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
markschwab
Level IV

How do I set line style in JSL?

I would like to set line style for a line graph based off a function of the column I use to overlay. For example, if I have data where the column that I use to overlay has values "Revenue_Jan", "Profit_Jan", "Revenue_Feb", "Profit_Feb", I want any "Revenue" graph to be dashed and any "Profit" graph to be dashed.

Can I set line style in this way using JSL?

1 ACCEPTED SOLUTION

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

Re: How do I set line style in JSL?

Here is an expansion of Jim's example that conditionally applies line style to the Overlay levels by looping over a list of levels.

In Graph Builder, each overlay level seems to be adressed by a number starting at 0. The order differs from the default if the Overlay column has a Value Ordering property. Thus, the ordering of levels needs to be considered when creating the list.

Names Default To Here(1);

// Example data table

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

dt << New Column("group",

    Character,

    Formula(

        If(

            :sex == "F" & :height < Col Mean(:height, :sex), "F short",

            :sex == "F" & :height >= Col Mean(:height, :sex), "F tall",

            :sex == "M" & :height < Col Mean(:height, :sex), "M short",

            "M tall"

        )

    )

);

// Graph builder with Overlay

OverlayCol = Column(dt, "group");

gb = Graph Builder(

    Size(528, 447),

    Show Control Panel(0),

    Variables(X(:age), Y(As Column(YCol)), overlay(group)),

    Elements(Line(X, Y)),

);

// Apply line style to overlay values that fulfill criteria

lstyle = "Dotted";

criteria = "M ";

Summarize(g = by(OverlayCol)); // List of overlay levels (alphabethical order)

// Uncomment below line if Value Ordering property is set for the Overlay column

// g=OverlayCol<<get property(value ordering); // List of overlay levels (custom order)

For(i = 1, i <= N Items(g), i++,

    If(Contains(g[i], criteria),

        gb << SendToReport(

            Dispatch({}, "400", ScaleBox,

                {Legend Model(4, Properties(i - 1, {Line Style(lstyle)}))}

            )

        )

    )

);

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How do I set line style in JSL?

Line style can easily be set in JSL.  Below is a simple script that shows you one way of changing the line style.

Names Default To Here( 1 );

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

YCol = "height";

// The value of lstyle can be set based upon

// the column being used for the Y column

// (i.e. If(YCol == "Profit", lstyle="Dotted", lstyle="Solid"))

lstyle = "Dotted";

Graph Builder(

       Size( 528, 447 ),

       Show Control Panel( 0 ),

       Variables( X( :age ), Y( As Column( YCol ) ) ),

       Elements( Line( X, Y, Legend( 4 ) ) ),

       SendToReport(

              Dispatch( {}, "400", ScaleBox,

              {Legend Model( 4, Properties( 0, {Line Style( lstyle )} ) )} )

       )

);


11554_pastedImage_0.png

Jim
markschwab
Level IV

Re: How do I set line style in JSL?


Hi Jim, thanks for the response. My issue is, in your example, you are explicitly telling the script which graph to change the line style of, in the Properties( 0, {Line Style( "Dotted" )} command. In the case I am interested in, I will not know ahead of time how many graphs there are - there could be 3, there could be 30, and I want to change the line style of each one based off the overlay value.

Is there a more general way to do that command, that selects some group instead of choosing one specific graph to change? Or, for example, could I somehow find the index of the graphs I am interested in, and run a loop that changes the line style of each?

For example, if I have three graphs, "Revenue_Jan", "Profit_Jan", and "Revenue_Feb" (and I don't know ahead of time how many "Revenue" graphs there will be,) is there a good way to find out that graph 0 and graph 2 both start with "Revenue", and run a loop that changes the style of both? Or is there any other way to do this kind of function?

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

Re: How do I set line style in JSL?

Here is an expansion of Jim's example that conditionally applies line style to the Overlay levels by looping over a list of levels.

In Graph Builder, each overlay level seems to be adressed by a number starting at 0. The order differs from the default if the Overlay column has a Value Ordering property. Thus, the ordering of levels needs to be considered when creating the list.

Names Default To Here(1);

// Example data table

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

dt << New Column("group",

    Character,

    Formula(

        If(

            :sex == "F" & :height < Col Mean(:height, :sex), "F short",

            :sex == "F" & :height >= Col Mean(:height, :sex), "F tall",

            :sex == "M" & :height < Col Mean(:height, :sex), "M short",

            "M tall"

        )

    )

);

// Graph builder with Overlay

OverlayCol = Column(dt, "group");

gb = Graph Builder(

    Size(528, 447),

    Show Control Panel(0),

    Variables(X(:age), Y(As Column(YCol)), overlay(group)),

    Elements(Line(X, Y)),

);

// Apply line style to overlay values that fulfill criteria

lstyle = "Dotted";

criteria = "M ";

Summarize(g = by(OverlayCol)); // List of overlay levels (alphabethical order)

// Uncomment below line if Value Ordering property is set for the Overlay column

// g=OverlayCol<<get property(value ordering); // List of overlay levels (custom order)

For(i = 1, i <= N Items(g), i++,

    If(Contains(g[i], criteria),

        gb << SendToReport(

            Dispatch({}, "400", ScaleBox,

                {Legend Model(4, Properties(i - 1, {Line Style(lstyle)}))}

            )

        )

    )

);

markschwab
Level IV

Re: How do I set line style in JSL?

Fantastic, thank you!

One thing I still don't understand - for me, your script only works when I change "{Legend Model(4..." to "{Legend Model{1...". Do you know what this "Legend Model" refers to? I can't find documentation on it anywhere.

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

Re: How do I set line style in JSL?

I did also notice that the number does not matter, at least not in the current example. I'm not sure what Legend Model refers to. Graph Builder is quite different from other platforms when it comes to scripting.