0

I am developing a simple application on Java EE platform using database as MYSQL and JFreeChart to generate 3D Bar Charts but 3D effect is visible but the bars are not seen on that background,thus I am unable to display the bars in bar chart and same is with when I try to do this with Pie Charts.

Here is mine code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="org.jfree.data.jdbc.JDBCCategoryDataset" %>
<%@ page import="org.jfree.chart.plot.PlotOrientation" %>
<%@ page import="org.jfree.chart.JFreeChart" %>
<%@ page import="org.jfree.chart.ChartUtilities" %>
<%@ page import="org.jfree.chart.ChartFactory" %>
<%

String connectionURL = "jdbc:mysql://localhost/tester?user=root&password=root&useUnicode=true&characterEncoding=utf-8"; 
Class.forName("com.mysql.jdbc.Driver"); 
Connection con = DriverManager.getConnection (connectionURL); 
String query = "SELECT * from charter";
JDBCCategoryDataset dataset = new JDBCCategoryDataset(con);
dataset.executeQuery(query);
JFreeChart chart = ChartFactory.createBarChart3D("Test", "Name", "ID",dataset, PlotOrientation.VERTICAL, true, true, false);
try { 
    ChartUtilities.saveChartAsJPEG(new File("E:/project/jfreechart3D/img/barchart_3D.jpeg"),chart,400, 300); 
    } 
catch (IOException e) {
    System.out.println("No chart creation.");
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<IMG SRC="E:/project/jfreechart3D/img/barchart_3D.jpeg" WIDTH="600" HEIGHT="400" BORDER="0" USEMAP="#chart" />
</body>
</html>
Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Mohit Garg
  • 1
  • 1
  • 3

1 Answers1

0

Instead, write a servlet that invokes one of the ChartUtilities methods such as writeChartAsJPEG() or writeChartAsPNG(). The former will be more compressed, but the latter will be sharper. There's an example here. Have your JSP include a tag where the src refers to your servlet.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045