【问题标题】:Bar chart with respect to Database关于数据库的条形图
【发布时间】:2012-05-28 06:06:17
【问题描述】:

这是我的表(在 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 页面中显示这个。

我们将非常感谢您的任何意见。

【问题讨论】:

  • 运行上面的代码,仍然得到一个异常:java.io.EOFException: Can not read response from server。预期读取 4 个字节,在连接意外丢失之前读取 0 个字节。
  • @Vivekanand:请用代码更新您的问题。没有人愿意阅读包含 10 行代码的评论。
  • 您的 JDBC URL 中的端口和数据库名称之间有空格。
  • 已更正,但事实并非如此。

标签: java mysql jsp jfreechart


【解决方案1】:

在您的查询中使用GROUP BY

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 2022-10-24
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多