// Or.... choose between a line graph and a bar graph depending upon
// whether the type of the domain is numeric.
XYSeriesCollection data = new XYSeriesCollection();
XYSeries series = new XYSeries(domainVariable);
for (Iterator it = trials.iterator(); it.hasNext();) {
Trial trial = (Trial) it.next();
if (trial.getException() != null) {
continue;
}
double time = trial.getRunTimeMillis();
String domainValue = (String) trial.getVariables().get(domainVariable);
series.add(Double.parseDouble(domainValue), time);
}
data.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart(title, domainVariable,
valueTitle, data, PlotOrientation.VERTICAL, false, false, false);
XYPlot plot = chart.getXYPlot();
plot.getRangeAxis().setUpperBound(maxTime + maxTime * 0.1);
double maxDomainValue = getMaxValue(comparativeResults, domainVariable);
plot.getDomainAxis().setUpperBound(maxDomainValue + maxDomainValue * 0.1);
return chart;
} else if (numVariables == 2) {
// Show a line graph with two series
XYSeriesCollection data = new XYSeriesCollection();
Set seriesValues = (Set) variableValues.get(seriesVariable);
for (Iterator it = seriesValues.iterator(); it.hasNext();) {
String seriesValue = (String) it.next();
XYSeries series = new XYSeries(seriesValue);
for (Iterator trialsIt = trials.iterator(); trialsIt.hasNext();) {
Trial trial = (Trial) trialsIt.next();
if (trial.getException() != null) {
continue;
}
Map variables = trial.getVariables();
if (variables.get(seriesVariable).equals(seriesValue)) {
double time = trial.getRunTimeMillis();
String domainValue = (String) trial.getVariables().get(
domainVariable);
series.add(Double.parseDouble(domainValue), time);
}
}
data.addSeries(series);
}
// TODO(tobyr) - Handle graphs above 2 variables