JFreeChart chart = ChartFactory.createTimeSeriesChart("TimeSeriesChart", "date", "smt_nt",xydataset,true, true,false);
XYPlot plot=chart.getXYPlot();
StandardXYItemRenderer renderer = new StandardXYItemRenderer(
StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,
ttg, urlg);
plot.setRenderer(renderer);
chart.setBackgroundPaint(java.awt.Color.white);
filename = ServletUtilities.saveChartAsPNG(chart,780,500, null, session);
// Write the image map to the PrintWriter
}
catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
public String generatePieChart(String title, HttpSession session)
{
DefaultPieDataset piedata = new DefaultPieDataset();
String filename = null;
try {
//dataset自添加
if ( dataset.getRowCount()>0)
{
for (int i=0;i<dataset.getRowCount();i++)
{
piedata.setValue(dataset.getCells(i,0),Double.valueOf((String)dataset.getCells(i,1)).doubleValue());
}
}
else{}
PiePlot3D plot = new PiePlot3D(piedata);
plot.setDepthFactor(0.05);
plot.setLabelGenerator(new StandardPieItemLabelGenerator(StandardPieItemLabelGenerator.DEFAULT_TOOLTIP_FORMAT));
plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0}/{1}k/{2}"));
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,plot, true);
filename = ServletUtilities.saveChartAsPNG(chart, 750, 500, null,session);
}
catch (Exception e)
{
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
public String generateStackedBarChart3D1(HttpSession session)
{
DefaultCategoryDataset stackedDateset= new DefaultCategoryDataset();
String filename = null;
try {
//dataset自添加
if ( dataset.getRowCount()>0)
{
for (int i=0;i<dataset.getRowCount();i++)
{
stackedDateset.addValue(Double.valueOf((String)dataset.getCells(i,2)).
doubleValue(),dataset.getCells(i,1),dataset.getCells(i,0));
}
}
else{}
JFreeChart chart =
ChartFactory.createStackedBarChart3D("StackedBarChart3D1", "date",
"smt_nt",stackedDateset, PlotOrientation.VERTICAL,true, true,true);
filename = ServletUtilities.saveChartAsPNG(chart,750,500, null,session);
}
catch (Exception e)
{
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
public String generateBarChart3D(HttpSession session)
{
DefaultCategoryDataset stacked1Dateset= new DefaultCategoryDataset();
String filename = null;
try {
//dataset自添加
if ( dataset.getRowCount()>0)
{
for (int i=0;i<dataset.getRowCount();i++)
{
stacked1Dateset.addValue(Double.valueOf((String)dataset.getCells(i,2)).
doubleValue(),dataset.getCells(i,1),dataset.getCells(i,0));
}
}
else{}
JFreeChart chart = ChartFactory.createBarChart3D("BarChart3D1", "date",
"smt_nt",stacked1Dateset, PlotOrientation.VERTICAL,true, true,true);
filename = ServletUtilities.saveChartAsPNG(chart,750,500, null,session);
}
catch (Exception e)
{
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
public String generateStackedBarChart3D2(HttpSession session)
{
String filename = null;
DefaultCategoryDataset stacked1Dateset= new DefaultCategoryDataset();
try {
if ( dataset.getRowCount()>0)
{
for (int i=0;i<dataset.getRowCount();i++)
{
stacked1Dateset.addValue(Double.valueOf((String)dataset.
getCells(i,2)).doubleValue(),dataset.getCells(i,1),dataset.getCells(i,0));
}
}
else{}
JFreeChart chart = ChartFactory.createStackedBarChart3D
("StackedBarChart3D1", "date", "smt_nt",stacked1Dateset, PlotOrientation.VERTICAL,true, true,true);
filename = ServletUtilities.saveChartAsPNG(chart,750,500, null,session);
}
catch (Exception e)
{
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
}
jsp:
<%
generatechart chart = new generatechart();
String piechart = chart.generatePieChart("PieChart",session);
String piechartURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + piechart;
String barchart3D = chart.generateBarChart3D(session);
String barchart3DURL = request.getContextPath() + "/servlet/DisplayChart?filename=" +barchart3D;
String stackedbarchart3D1 = chart.generateStackedBarChart3D1(session);
String stackedbarchart3D1URL = request.getContextPath() + "/servlet/DisplayChart?filename=" +stackedbarchart3D1;
String stackedbarchart3D2 = chart.generateStackedBarChart3D2(session);
String stackedbarchart3D2URL = request.getContextPath() + "/servlet/DisplayChart?filename=" + stackedbarchart3D2;
String linechart = chart.generateXYChart(session,new PrintWriter(out));
String linechartURL= request.getContextPath() + "/servlet/DisplayChart?filename=" + linechart;
%>
<HTML>
<HEAD>
<TITLE>yjf/jchart/jfreechart</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= piechartURL %>" width=750 height=500 border=0 ">
</P>
<P ALIGN="CENTER">
<img src="<%= barchart3DURL%>" width=750 height=500 border=0 ">
</P>
<P ALIGN="CENTER">
<img src="<%= stackedbarchart3D1URL %>" width=750 height=500 border=0 ">
</P>
<P ALIGN="CENTER">
<img src="<%=stackedbarchart3D2URL%>" width=750 height=500 border=0 ">
</P>
<P ALIGN="CENTER">
<img src="<%= linechartURL%>" width=700 height=500 border=0 usemap="#<%=linechart%>">
</P>