I used a component called "jchart" to produce pie chart and wanna output jpg to browser instead of making a file.
Here is the code:
<%@ page contentType="image/jpeg; charset=gb2312" %>
<%@ page import="org.jCharts.chartData.ChartDataException" %>
<%@ page import="org.jCharts.chartData.PieChartDataSet" %>
<%@ page import="org.jCharts.encoders.*" %>
<%@ page import="org.jCharts.nonAxisChart.PieChart2D" %>
<%@ page import="org.jCharts.properties.*" %>
<%@ page import="java.awt.*" %>
<%@ page import="java.io.*"%>
<%
try
{
PieChart2DProperties properties=new PieChart2DProperties();
LegendProperties legendProperties=new LegendProperties();
legendProperties.setNumColumns(2);
legendProperties.setPlacement(LegendProperties.RIGHT);
ChartProperties chartProperties=new ChartProperties();
int width = 550;
int height = 350;
double[] data = new double[]{40, 15, 35, 65, 59};
Paint[] paints = new Paint[]{Color.blue, Color.red, Color.green, Color.yellow, Color.white};
String[] labels = {"BMW", "Honda", "Lexus", "Audi", "Acura"};
PieChartDataSet piechartds=new PieChartDataSet( "Cars That Own!", data, labels, paints, properties );
PieChart2D pieChart2D = new PieChart2D(piechartds, legendProperties, chartProperties, width, height );
//out.println("width="+width);
//out.println("height="+height);
//FileOutputStream fo=new FileOutputStream(new File("sample1.jpg");
//response.setContentType("image/jpeg"
DataOutputStream imagestream=new DataOutputStream(response.getOutputStream());
JPEGEncoder13.encode(pieChart2D,1.0f,imagestream);
imagestream.flush();
System.out.println("success!"
}
catch(Throwable throwable)
{
throwable.printStackTrace();
}
%>
weblogic reported a java.net.exception,said that read file failed
and if i use a FileOutputStream to replace this DataOutputStream and write a file on server,everything is ok
can anyone hellp me?
Here is the code:
<%@ page contentType="image/jpeg; charset=gb2312" %>
<%@ page import="org.jCharts.chartData.ChartDataException" %>
<%@ page import="org.jCharts.chartData.PieChartDataSet" %>
<%@ page import="org.jCharts.encoders.*" %>
<%@ page import="org.jCharts.nonAxisChart.PieChart2D" %>
<%@ page import="org.jCharts.properties.*" %>
<%@ page import="java.awt.*" %>
<%@ page import="java.io.*"%>
<%
try
{
PieChart2DProperties properties=new PieChart2DProperties();
LegendProperties legendProperties=new LegendProperties();
legendProperties.setNumColumns(2);
legendProperties.setPlacement(LegendProperties.RIGHT);
ChartProperties chartProperties=new ChartProperties();
int width = 550;
int height = 350;
double[] data = new double[]{40, 15, 35, 65, 59};
Paint[] paints = new Paint[]{Color.blue, Color.red, Color.green, Color.yellow, Color.white};
String[] labels = {"BMW", "Honda", "Lexus", "Audi", "Acura"};
PieChartDataSet piechartds=new PieChartDataSet( "Cars That Own!", data, labels, paints, properties );
PieChart2D pieChart2D = new PieChart2D(piechartds, legendProperties, chartProperties, width, height );
//out.println("width="+width);
//out.println("height="+height);
//FileOutputStream fo=new FileOutputStream(new File("sample1.jpg");
//response.setContentType("image/jpeg"
DataOutputStream imagestream=new DataOutputStream(response.getOutputStream());
JPEGEncoder13.encode(pieChart2D,1.0f,imagestream);
imagestream.flush();
System.out.println("success!"
}
catch(Throwable throwable)
{
throwable.printStackTrace();
}
%>
weblogic reported a java.net.exception,said that read file failed
and if i use a FileOutputStream to replace this DataOutputStream and write a file on server,everything is ok
can anyone hellp me?