Hi,
My application requires creation of charts with the input from a form.I am able to create the chart and display it, but i have to save the created charts in some folder. I am using a servlet to create the chart.But if i deployed it in tomcat i am not able to save chart inside webapps.Kindly resolve this problem. Any suggestions will be greatly appreciated.
Save chart inside webapps
-
- Posts: 49
- Joined: Thu Jul 08, 2004 8:54 am
- Location: France
you 'd better not save the chart.
have a close look at this
http://www.jfree.org/phpBB2/viewtopic.p ... jsp+webapp
have a close look at this
http://www.jfree.org/phpBB2/viewtopic.p ... jsp+webapp
Why to Save the chart?
hi! Arun,
get me clarified first, why do you wish to save those charts at all .
If you go on saving the images of these charts your directory will become as huge as you you will feel some day that you cannot wieght he burden of these images.
It's better you present the images on to the webpages with the help of Servlets or JSP and , it's enough.
Or your need is different, then there is a way to store the graphs as HTML images .I'll send a sample program which you mught find useful.
package org.jfree.chart.demo;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
/**
* A demo showing how to create an HTML image map for a bar chart.
*/
public class ImageMapDemo1 {
/**
* Default constructor.
*/
public ImageMapDemo1() {
super();
}
/**
* Starting point for the demo.
*
* @param args ignored.
*/
public static void main(final String[] args) {
// create a chart
final double[][] data = new double[][] {
{56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0},
{37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0},
{43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0}
};
final CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
"Series ", "Type ", data
);
JFreeChart chart = null;
final boolean drilldown = true;
if (drilldown) {
final CategoryAxis categoryAxis = new CategoryAxis("Category");
final ValueAxis valueAxis = new NumberAxis("Value");
final BarRenderer renderer = new BarRenderer();
renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
plot.setOrientation(PlotOrientation.VERTICAL);
chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
else {
chart = ChartFactory.createBarChart(
"Vertical Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true,
false
);
}
chart.setBackgroundPaint(java.awt.Color.white);
// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * http://www.object-refinery.com/jfreechart/guide.html *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************
// save it to an image
try {
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
final File file1 = new File("barchart100.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
// write an HTML page incorporating the image with an image map
final File file2 = new File("barchart100.html");
final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
final PrintWriter writer = new PrintWriter(out);
writer.println("<HTML>");
writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
writer.println("<BODY>");
// ChartUtilities.writeImageMap(writer, "chart", info);
writer.println("<IMG SRC=\"barchart100.png\" "
+ "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
writer.println("</BODY>");
writer.println("</HTML>");
writer.close();
}
catch (IOException e) {
System.out.println(e.toString());
}
}
you canspecify the directory in to which the image has to be saved.
regards,
MJ
get me clarified first, why do you wish to save those charts at all .
If you go on saving the images of these charts your directory will become as huge as you you will feel some day that you cannot wieght he burden of these images.
It's better you present the images on to the webpages with the help of Servlets or JSP and , it's enough.
Or your need is different, then there is a way to store the graphs as HTML images .I'll send a sample program which you mught find useful.
package org.jfree.chart.demo;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
/**
* A demo showing how to create an HTML image map for a bar chart.
*/
public class ImageMapDemo1 {
/**
* Default constructor.
*/
public ImageMapDemo1() {
super();
}
/**
* Starting point for the demo.
*
* @param args ignored.
*/
public static void main(final String[] args) {
// create a chart
final double[][] data = new double[][] {
{56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0},
{37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0},
{43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0}
};
final CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
"Series ", "Type ", data
);
JFreeChart chart = null;
final boolean drilldown = true;
if (drilldown) {
final CategoryAxis categoryAxis = new CategoryAxis("Category");
final ValueAxis valueAxis = new NumberAxis("Value");
final BarRenderer renderer = new BarRenderer();
renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
plot.setOrientation(PlotOrientation.VERTICAL);
chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
else {
chart = ChartFactory.createBarChart(
"Vertical Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true,
false
);
}
chart.setBackgroundPaint(java.awt.Color.white);
// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * http://www.object-refinery.com/jfreechart/guide.html *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************
// save it to an image
try {
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
final File file1 = new File("barchart100.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
// write an HTML page incorporating the image with an image map
final File file2 = new File("barchart100.html");
final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
final PrintWriter writer = new PrintWriter(out);
writer.println("<HTML>");
writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
writer.println("<BODY>");
// ChartUtilities.writeImageMap(writer, "chart", info);
writer.println("<IMG SRC=\"barchart100.png\" "
+ "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
writer.println("</BODY>");
writer.println("</HTML>");
writer.close();
}
catch (IOException e) {
System.out.println(e.toString());
}
}
you canspecify the directory in to which the image has to be saved.
regards,
MJ
Master Java