0

这是我的表(在 mysql 中):

mysql> select device from user_management;
+--------+
| device |
+--------+
| APPLE  |
| HTC    |
| HTC    |
| NOKIA  |
| APPLE  |
| APPLE  |
+--------+
6 rows in set (0.00 sec)

我的代码是

<%
String query1 = "select device,count(device) from user_management where  device='"+APPLE+"'";
JDBCCategoryDataset dataset = new JDBCCategoryDataset("jdbc:mysql://localhost:8080/apps","com.mysql.jdbc.Driver","root","root");
dataset.executeQuery(query1);
System.out.println("query1");
JFreeChart chart = ChartFactory.createBarChart3D("Device  Statictics","Device","Count",dataset,PlotOrientation.VERTICAL,true,true,false);
try
{
ChartUtilities.saveChartAsJPEG(new File("D:/dvc.png"),chart,500,400);
}
catch(IOException e)
{
System.out.println(".....there is a problem in your chart. ");
}
%>

并且基于设备名称(APPLE,NOKIA,SAMSUNG),我想创建一个条形图,显示“设备编号 VS 设备”。我想在 jsp 页面中显示这个。

您的任何意见将不胜感激。

4

1 回答 1

2

GROUP BY在您的查询中使用。

SELECT device, count(device) FROM user_management GROUP BY device;

使用查询从 构建合适的 JDBC 数据集org.jfree.data.jdbc,并使用该数据集创建图表。

于 2012-05-28T13:50:01.710 回答