Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: Beginner questions re saving/storing/exporting graphs in Windows
From
Garry Anderson <[email protected]>
To
[email protected]
Subject
RE: st: Beginner questions re saving/storing/exporting graphs in Windows
Date
Mon, 18 Oct 2010 20:30:19 +1100
The basic.html file that is created by Maarten's code does not seem to
contain the .png files when the basic.html file is sent to others. Ben's
requirement was that he sends the basic.html file to other users so that
they can see the graphs.
Is there a method to embed the .png files into the .html file so that
when the .html file is opened on another computer the graphs are
visible? I am using Windows XP.
Cheers, Garry
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Maarten buis
Sent: Thursday, 14 October 2010 7:50 PM
To: [email protected]
Subject: Re: st: Beginner questions re saving/storing/exporting graphs
in Windows
--- On Thu, 14/10/10, Benhoen2 wrote:
> I need a quick primer on how to get multiple graphs from the graph
> window into a file that then I can save for later, send to others.
The easiest way of doing that is probably to create a .html file.
To create such a file you can use the -file open-, -file write-, and
-file close- commands.
A minimum file will use two html tags (="html commands"):
1) <img src = "file.ext">, which includes the graph stored in file.ext
in the webpage. To do that you need to have stored your graphs using an
extension that can be readily read in webbrowsers, .png is a common
format for that.
2) <br> tells that you want to start a new line.
An example of such a miminum file looks like this. The code creates an
html document c:\temp\basic.html.
*------------begin basic example ------------------- cd "c:\temp"
file open basic using basic.html, write replace
sysuse auto, clear
foreach var of varlist mpg-trunk {
hist `var'
graph export `var'.png, replace
file write basic `"<img src="`var'.png"> <br>"' _n } file close
basic
*----------- end basic example ----------------------
If you know a bit more html, you can add more bells and wistles, like
the example below:
*------ begin example with bells and wistles ---------- cd "c:\temp"
file open graphs using graphs.html, write replace file write graphs
`"<html><body>"'
file write graphs `"<p>You can write comments on top of the file</p>"'
_n
sysuse auto, clear
foreach var of varlist mpg-trunk {
hist `var'
graph export `var'.png, replace
file write graphs `"<p>You can also type some comments above each"'
file write graphs `" graph, like the name of the variable being"'
file write graphs `" plotted: <b>`var'</b>.</p>"' _n
file write graphs `"<img src="`var'.png" width="484" height="322""'
file write graphs `" alt="histogram of `var'"> <br>"' _n }
file write graphs `"<p>You can write comments at the bottom"'
file write graphs `"of the file</p>"' _n file write graphs
`"</body></html>"'
file close graphs
*------ end example with bells and wistles ----------
A text that expands on this basic approach can be found in:
Rosa Gini and Jacopo Pasquini (2006) "Automatic generation of
documents", The Stata Journal, 6(1):22--39.
<http://www.stata-journal.com/article.html?article=pr0020>
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/