
I try to create a BarChart using a JDBCCategoryDataset and enrich it with the results of another JDBCCategoryDataset, as follows, but without any success:
-------------------------------------------------------------
String sql1="select label, value from table where condition1";
String sql2="select value from table where condition2";
con = DriverManager.getConnection(url, "schema", "password");
JDBCCategoryDataset data1 = new JDBCCategoryDataset(con);
JDBCCategoryDataset data2 = new JDBCCategoryDataset(con);
data1.executeQuery(sql1);
data2.executeQuery(sql2);
// this creates a chart with the category=label and value=value from data1
JFreeChart chart = ChartFactory.createBarChart(
"Vertical Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
data, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
// how can I put in the same chart also the values from the 2nd dataset?
// because I want to compare the values of the 2 series on the same chart
// tried the following but no result...
cplot = (CategoryPlot) chart.getCategoryPlot(); // the plot
cplot.setDataset(0,data1);
cplot.setDataset(1,data2);
-----------------------------------------
Any hint would be appreciated,
TIA