Code: Select all
public static JFreeChart CreateChart( String strSessionMouseID){
Connection conn = null;
ResultSet rsRecordSet=null;
Statement statStatement = null;
DecimalFormat dfPercent = new DecimalFormat("0.0%");
String strQuery = "Select SESSIONTRIALNUM, SESSIONDAYNUM, FAILURERATE FROM "
+ GlobalDataStore.strRunDataTblName + " WHERE SESSIONMOUSEID LIKE '" + strSessionMouseID + "%'";
conn = DerbyUtils.BootDatabase(conn);
String strChartName = strSessionMouseID + " Trial Data";
System.out.println(strQuery);
try {
statStatement = conn.createStatement();
rsRecordSet = statStatement.executeQuery(strQuery); //execute the query
if (!rsRecordSet.next()){
System.out.println("No mice in database.");
}
else{
dataset.clear();
do{
dataset.addValue(Double.valueOf(rsRecordSet.getString("FAILURERATE")),
rsRecordSet.getString("SESSIONTRIALNUM"), rsRecordSet.getString("SESSIONDAYNUM"));
}while (rsRecordSet.next());
}
rsRecordSet.close();
//chart = ChartFactory.createLineChart(
chart = ChartFactory.createBarChart(
strChartName, // chart title
"Day", // domain axis label
"Miss Percentage", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
chart.setTitle(strChartName);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
BarRenderer bRenderer = (BarRenderer)plot.getRenderer();
// LineAndShapeRenderer renderer = (LineAndShapeRenderer)plot.getRenderer();
CategoryItemRenderer cIRenderer = plot.getRenderer();
CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", dfPercent);
cIRenderer.setItemLabelGenerator(generator);
ShowBarLabels(true);
plot.setDataset(dataset);
//bRenderer.setItemMargin(0.5);
conn.close();
if(chart == null) System.out.println("Chart==null");
return chart;
} catch (SQLException e) {
System.out.println("Error in CreateChart");
e.printStackTrace();
return null;
}
}