Below is my sample coding that had created! but there is a problem that the pie chart doesn`t display out! what is the mistake for the coding?
Thankx!
import com.jrefinery.data.PieDataset;
import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFrame;
import com.jrefinery.chart.ChartUtilities;
import com.jrefinery.chart.*;
import com.jrefinery.data.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.math.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class pie_servlet extends HttpServlet{
ServletContext context=null;
Connection con = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
context=config.getServletContext();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@solaris8dev.mecomb.po.my:1521:MEC_CRM",
"crmdev", "crmdev123");
}
catch (ClassNotFoundException e)
{
throw new UnavailableException(this, "Couldn't load the database driver");
}
catch (SQLException e)
{
throw new UnavailableException(this, "Couldn't get db connection");
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("IMAGE/GIF");
int type=1;
int width = 400;
int height = 300;
String query = request.getParameter("query");
query="SELECT * FROM com";
JdbcPieDataset chartData = new JdbcPieDataset(con);
chartData.executeQuery(query);
// create a chart...
JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart", chartData, true);
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
out.close();
}
}
Pie Chart
Re: Pie Chart
Is your query returning valid data? Comment out your dataset, and add in something like this:
DefaultPieDataset chartData = new DefaultPieDataset();
chartData.setValue("One", new Double(43.2));
chartData.setValue("Two", new Double(10.0));
...just to check if it is a problem with the dataset.
Regards,
DG
DefaultPieDataset chartData = new DefaultPieDataset();
chartData.setValue("One", new Double(43.2));
chartData.setValue("Two", new Double(10.0));
...just to check if it is a problem with the dataset.
Regards,
DG
Re: Pie Chart
David Gilbert :
ya i already test for the coding, but once i connect to the database the pie chart does not appear in the servlet! so what modification have to do in the coding?
ya i already test for the coding, but once i connect to the database the pie chart does not appear in the servlet! so what modification have to do in the coding?