有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

关于数据库的java条形图

这是我的表(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. ");
}
%>

根据设备名称(苹果、诺基亚、三星),我想创建一个条形图,显示“设备与设备的数量”。 我想在jsp页面中显示这一点

非常感谢贵方的任何意见


共 (1) 个答案

  1. # 1 楼答案

    在查询中使用GROUP BY

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

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