Hy *
I want to generate Charts with jFreeChart and send them to varios eMailadresses. This Application will run via cron on my Server.
Is it possible to let jFreeChart generate this Charts and send them as an .jpg appended to an eMail??
If Yes, can you gif me an Tip how to do.
Thanks very much
\Robert
Send Charts via eMail
Re: Send Charts via eMail
Hi Robert,
Yes, you can save the charts in a variety of formats. They are described in the documentation for jFreeChart. I am including the two methods that I use to first create an SVG image of the chart and then convert it to JPEG. I hope this will help point you in the direction you want to go.
Regards.
Frank
public void saveJPEG(File imageFile, JFreeChart chart) {
String svgFileName = createSVGFileName(imageFile);
File svgFile = new File(svgFileName);
//
// create SVG image from selected chart
//
saveSVG(svgFile, chart);
//
try {
JPEGTranscoder t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.
);
String svgURI = svgFile.toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
OutputStream ostream = new FileOutputStream(imageFile.toString());
TranscoderOutput output = new TranscoderOutput(ostream);
t.transcode(input, output);
ostream.flush();
ostream.close();
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
} catch (TranscoderException te) {
System.err.println(te.getMessage());
}
//
// remove the SVG file after JPEG file is created
//
svgFile.delete();
}
public void saveSVG(File imageFile, JFreeChart chart) {
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);
boolean useCSS = true;
try {
Writer out = new OutputStreamWriter(new FileOutputStream(imageFile), "UTF-8");
svgGenerator.stream(out, useCSS);
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
}
Yes, you can save the charts in a variety of formats. They are described in the documentation for jFreeChart. I am including the two methods that I use to first create an SVG image of the chart and then convert it to JPEG. I hope this will help point you in the direction you want to go.
Regards.
Frank
public void saveJPEG(File imageFile, JFreeChart chart) {
String svgFileName = createSVGFileName(imageFile);
File svgFile = new File(svgFileName);
//
// create SVG image from selected chart
//
saveSVG(svgFile, chart);
//
try {
JPEGTranscoder t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.

String svgURI = svgFile.toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
OutputStream ostream = new FileOutputStream(imageFile.toString());
TranscoderOutput output = new TranscoderOutput(ostream);
t.transcode(input, output);
ostream.flush();
ostream.close();
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
} catch (TranscoderException te) {
System.err.println(te.getMessage());
}
//
// remove the SVG file after JPEG file is created
//
svgFile.delete();
}
public void saveSVG(File imageFile, JFreeChart chart) {
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);
boolean useCSS = true;
try {
Writer out = new OutputStreamWriter(new FileOutputStream(imageFile), "UTF-8");
svgGenerator.stream(out, useCSS);
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
}
Re: Send Charts via eMail
I think sending charts is not a good idea as it takes a lot of size. Send them a link for the charts and when the link is clicked display 1 chart or display all the charts at a time. Just a thought.
Thanks,
Navin Pathuru
Thanks,
Navin Pathuru