与数据库相关的条形图



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

根据设备名称(苹果,诺基亚,三星),我想创建一个条形图,该条形图将显示"否"。设备VS设备"。我想在 jsp 页面中显示这一点。

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

查询中使用GROUP BY

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

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

相关内容

  • 没有找到相关文章

最新更新