使用数据库的条形图不显示
Barchart using database doesn't show
我想使用 mysql 数据库和 Jfreechart 创建图表,这是我使用的代码:
try {
String query =
"Select id,Prop_menages_Urbains_Proprietaires from fes";
JDBCCategoryDataset dataset =
new JDBCCategoryDataset(
DBConnection.DBConnection(),
query
);
JFreeChart chart =
ChartFactory.createBarChart(
"test",
"id",
"Prop_menages_Urbains_Proprietaires",
dataset,
PlotOrientation.VERTICAL,
false,
true,
true
);
BarRenderer render = null;
CategoryPlot plot = null;
render = new BarRenderer();
ChartFrame fram =
new ChartFrame("test", chart);
fram.setVisible(true);
fram.setSize(600,650);
}
catch(Exception ex) {
System.out.println("Erreur: " + ex);
}
虽然代码语法没有错误,但执行后条形图没有显示
有什么帮助吗?
更新:我尝试了相同的代码,但这次我使用了数据库中的其他列并且它有效,另一个知道它们都是数字的问题是什么
JDBCCategoryDataset
API 指定:
The SQL query must return at least two columns. The first column will be the category name and remaining columns values (each column represents a series).
这个完整的example,你适配成功,说明效果。那么问题就变成了,
What's the issues with the other one knowing that they're all numbers?
、executeQuery()
source shows how each of the java.sql.Types
is mapped to a numeric value: a numeric type becomes a Number
directly, a date type becomes a Number
representing milliseconds from the Java epoch、字符类型转换使用Double.valueOf()
; default
是 null
.
在这种情况下,请验证 Prop_menages_Urbains_Proprietaires
具有适合转换为数值的 SQL 类型。
我想使用 mysql 数据库和 Jfreechart 创建图表,这是我使用的代码:
try {
String query =
"Select id,Prop_menages_Urbains_Proprietaires from fes";
JDBCCategoryDataset dataset =
new JDBCCategoryDataset(
DBConnection.DBConnection(),
query
);
JFreeChart chart =
ChartFactory.createBarChart(
"test",
"id",
"Prop_menages_Urbains_Proprietaires",
dataset,
PlotOrientation.VERTICAL,
false,
true,
true
);
BarRenderer render = null;
CategoryPlot plot = null;
render = new BarRenderer();
ChartFrame fram =
new ChartFrame("test", chart);
fram.setVisible(true);
fram.setSize(600,650);
}
catch(Exception ex) {
System.out.println("Erreur: " + ex);
}
虽然代码语法没有错误,但执行后条形图没有显示 有什么帮助吗?
更新:我尝试了相同的代码,但这次我使用了数据库中的其他列并且它有效,另一个知道它们都是数字的问题是什么
JDBCCategoryDataset
API 指定:
The SQL query must return at least two columns. The first column will be the category name and remaining columns values (each column represents a series).
这个完整的example,你适配成功,说明效果。那么问题就变成了,
What's the issues with the other one knowing that they're all numbers?
、executeQuery()
source shows how each of the java.sql.Types
is mapped to a numeric value: a numeric type becomes a Number
directly, a date type becomes a Number
representing milliseconds from the Java epoch、字符类型转换使用Double.valueOf()
; default
是 null
.
在这种情况下,请验证 Prop_menages_Urbains_Proprietaires
具有适合转换为数值的 SQL 类型。