Adding a picture as a background of a graphDear All,
I wrote the following script. After opening a data table, it takes the data and creates a graph by using the graph builder. Then it loads a picture which has the same name as the opened data table and use that picture as a background for the graph.
In order to make the script work, I had to add to the data table name the file extension .png as part of the name. So I had to name both the picture and the data table by adding .png in their name (the picture file has the extension .png).
For example, if the name of the picture is sample.png, I had to change it into sample.png.png.
Of course I do not like this but if I do not make this change jmp says that it can’t find the picture file.
I am sure the problem can be solved in a cleaner way.
Thanks a lot for any help.
Names Default To Here(1);
dt=Current Data Table();
gb = dt <<
Graph Builder(
Variables( X( :x ), Y( :y ), Overlay( :track ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch(
{},
"x",
ScaleBox,
{Min( 0 ), Max( 280 ), Inc( 50 ), Minor Ticks( 1 )}
),
Dispatch(
{},
"y",
ScaleBox,
{Min( 0 ), Max( 265 ), Inc( 50 ), Minor Ticks( 1 )}
),
Dispatch( {}, "Graph Builder", FrameBox, {Transparency( 0.05 )} )
)
);
frame = (gb << report)[FrameBox( 1 )];
n = dt << Get Name();
img = newImage(n);
img<<ROTATE></ROTATE>
Mass CustomizationRe: Adding a picture as a background of a graphMaybe one of these will work for you:
filename = "testname.html";
Substr(filename, 1, Contains(filename, ".")-1);
Left(filename, Length(fileName) - 5);
Word(1, filename, ".");
Check Scripting Index for more information what the functions do
Re: Adding a picture as a background of a graphMany thanks, this worked and I solved my problem.
Do you know how I can get rid of the file extension in a text string? I have a script that reads the names of the picture files in a folder and put their names in a vector. Each name contains also the extension. Is there a simple command to eliminate the last four letters of a text string?
Many thanks,
Marcello.
Re: Adding a picture as a background of a graphMany thanks!Re: Adding a picture as a background of a graphOn Windows, the Get Name() message to a data table returns only the table name, without the ".jmp" appended.
Names Default To Here( 1 );
dt = Open( "$DESKTOP/Big Class.jmp" );
Show( dt << get name() );
Log:
//:*/
Names Default To Here( 1 );
dt = Open( "$DESKTOP/Big Class.jmp" );
Show( dt << get name() );
/*:
dt << get name() = "Big Class";
So, you'll need to append the ".png" to get a complete filename for New Image().
Here's an example using Big Class (copied to your desktop) and the attached Big Class.png file here.
Names Default To Here( 1 );
dt = Open( "$DESKTOP/Big Class.jmp" );
gb = dt << Graph Builder(
Variables( X( :weight ), Y( :height ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 5 ) ), Smoother( X, Y, Legend( 6 ) ) ),
SendToReport( Dispatch( {}, "Graph Builder", FrameBox, {Transparency( 0.5 )} ) )
);
frame = (gb << report)[FrameBox( 1 )];
n = dt << Get Name();
img = New Image( "$DESKTOP/" || n || ".png" );
frame << Add Image(
image( img ),
Bounds(
Left( 61.2587412587413 ),
Right( 179.370629370629 ),
Top( 70.8292080975384 ),
Bottom( 48.5033161162993 )
),
SetSize( {799, 620} )
);
NB: On the Mac, <Substitute Into() to replace the ".jmp" with ".png".
Names Default To Here( 1 );
dt = Open( "~/Desktop/Big Class.jmp" );
gb = dt << Graph Builder(
Variables( X( :weight ), Y( :height ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 5 ) ), Smoother( X, Y, Legend( 6 ) ) ),
SendToReport( Dispatch( {}, "Graph Builder", FrameBox, {Transparency( 0.5 )} ) )
);
frame = (gb << report)[FrameBox( 1 )];
n = dt << Get Name();
Substitute Into( n, ".jmp", ".png" );
img = New Image( "~/Desktop/" || n );
//img<<ROTATE></ROTATE>
Re: Adding a picture as a background of a graphHi,
The issue is that the variable "n" is a string, not an image even after calling the New Image. I have not found a way to convert directly a string into an image but you can create a dummy txtb = Text Box (n), and then get the picture of that object txtimg = tctb << Get Picture, and finally use the txtimg variable as you background.
I hope it helps. Others may have more elegant ways to tackle this.
Best,
TS