关于在Eclipse中使用JFreechart和mysql数据库显示条形图/扇形图 [英] Regarding bar chart/pie chart display using JFreechart and mysql database in eclipse
问题描述
我正在使用数据库作为MYSQL和JFreeChart在Java EE平台上开发一个简单的应用程序以生成3D条形图,但是3D效果可见,但是在该背景上看不到条形图,因此我无法在条形图中显示条形图当我尝试通过饼图进行操作时也是如此.
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.
这是我的代码:
<%@ 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>
推荐答案
相反,编写一个Servlet来调用此处有一个示例.让您的JSP包含一个标签,其中src
指向您的servlet.
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.
这篇关于关于在Eclipse中使用JFreechart和mysql数据库显示条形图/扇形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!