use of org.opennms.netmgt.config.charts.SeriesDef in project opennms by OpenNMS.
the class ChartUtils method buildCategoryDataSet.
/**
* @param chartConfig
* @param baseDataSet
* @throws SQLException
*/
private static DefaultCategoryDataset buildCategoryDataSet(BarChart chartConfig) throws SQLException {
DefaultCategoryDataset baseDataSet = new DefaultCategoryDataset();
/*
* Configuration can contain more than one series. This loop adds
* single series data sets returned from sql query to a base data set
* to be displayed in a the chart.
*/
Connection conn = null;
try {
conn = DataSourceFactory.getInstance().getConnection();
Iterator<SeriesDef> it = chartConfig.getSeriesDefCollection().iterator();
while (it.hasNext()) {
SeriesDef def = it.next();
JDBCCategoryDataset dataSet = new JDBCCategoryDataset(conn, def.getJdbcDataSet().getSql());
for (int i = 0; i < dataSet.getRowCount(); i++) {
for (int j = 0; j < dataSet.getColumnCount(); j++) {
baseDataSet.addValue(dataSet.getValue(i, j), def.getSeriesName(), dataSet.getColumnKey(j));
}
}
}
} finally {
if (conn != null) {
conn.close();
}
}
return baseDataSet;
}
use of org.opennms.netmgt.config.charts.SeriesDef in project opennms by OpenNMS.
the class ChartUtils method customizeSeries.
/**
* @param barChart TODO
* @param chartConfig
*/
private static void customizeSeries(JFreeChart barChart, BarChart chartConfig) {
/*
* Set the series colors and labels
*/
CategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0"));
SeriesDef[] seriesDefs = chartConfig.getSeriesDef();
CustomSeriesColors seriesColors = null;
if (chartConfig.getSeriesColorClass().isPresent()) {
try {
seriesColors = (CustomSeriesColors) Class.forName(chartConfig.getSeriesColorClass().get()).newInstance();
} catch (InstantiationException e) {
LOG.error("getBarChart: Couldn't instantiate configured CustomSeriesColors class: {}", seriesColors, e);
} catch (IllegalAccessException e) {
LOG.error("getBarChart: Couldn't instantiate configured CustomSeriesColors class: {}", seriesColors, e);
} catch (ClassNotFoundException e) {
LOG.error("getBarChart: Couldn't instantiate configured CustomSeriesColors class: {}", seriesColors, e);
}
}
for (int i = 0; i < seriesDefs.length; i++) {
SeriesDef seriesDef = seriesDefs[i];
Paint paint = Color.BLACK;
if (seriesColors != null) {
Comparable<?> cat = (Comparable<?>) ((BarRenderer) barChart.getCategoryPlot().getRenderer()).getPlot().getCategories().get(i);
paint = seriesColors.getPaint(cat);
} else {
Rgb rgb = seriesDef.getRgb().get();
paint = new Color(rgb.getRed().getRgbColor(), rgb.getGreen().getRgbColor(), rgb.getBlue().getRgbColor());
}
((BarRenderer) barChart.getCategoryPlot().getRenderer()).setSeriesPaint(i, paint);
((BarRenderer) barChart.getCategoryPlot().getRenderer()).setSeriesItemLabelsVisible(i, seriesDef.getUseLabels());
((BarRenderer) barChart.getCategoryPlot().getRenderer()).setSeriesItemLabelGenerator(i, itemLabelGenerator);
}
}
Aggregations