use of org.opennms.netmgt.config.charts.Rgb in project opennms by OpenNMS.
the class ChartUtils method setPlotBackgroundColor.
private static void setPlotBackgroundColor(BarChart chartConfig, JFreeChart chart) {
if (chartConfig.getPlotBackgroundColor().isPresent()) {
final PlotBackgroundColor bgColor = chartConfig.getPlotBackgroundColor().get();
final Optional<Rgb> rgb = bgColor.getRgb();
if (rgb.isPresent()) {
final Red red = rgb.get().getRed();
final Blue blue = rgb.get().getBlue();
final Green green = rgb.get().getGreen();
chart.getPlot().setBackgroundPaint(new Color(red.getRgbColor(), green.getRgbColor(), blue.getRgbColor()));
}
}
}
use of org.opennms.netmgt.config.charts.Rgb 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 if (seriesDef.getRgb().isPresent()) {
final 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