Search in sources :

Example 6 with BarChart

use of org.opennms.netmgt.config.charts.BarChart in project opennms by OpenNMS.

the class ChartUtils method getBarChartPNG.

/**
 * Helper method that returns the JFreeChart to an output stream written in JPEG format.
 *
 * @param chartName a {@link java.lang.String} object.
 * @param out a {@link java.io.OutputStream} object.
 * @throws java.io.IOException if any.
 * @throws java.sql.SQLException if any.
 */
public static void getBarChartPNG(String chartName, OutputStream out) throws IOException, SQLException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    if (chartConfig.getChartBackgroundColor().isPresent()) {
        setChartBackgroundColor(chartConfig, chart);
    }
    if (chartConfig.getPlotBackgroundColor().isPresent()) {
        setPlotBackgroundColor(chartConfig, chart);
    }
    ImageSize imageSize = chartConfig.getImageSize();
    int hzPixels;
    int vtPixels;
    if (imageSize == null) {
        hzPixels = 400;
        vtPixels = 400;
    } else {
        hzPixels = imageSize.getHzSize().getPixels();
        vtPixels = imageSize.getVtSize().getPixels();
    }
    ChartUtilities.writeChartAsPNG(out, chart, hzPixels, vtPixels, false, 6);
}
Also used : ImageSize(org.opennms.netmgt.config.charts.ImageSize) BarChart(org.opennms.netmgt.config.charts.BarChart) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Aggregations

BarChart (org.opennms.netmgt.config.charts.BarChart)6 JFreeChart (org.jfree.chart.JFreeChart)5 Paint (java.awt.Paint)4 ImageSize (org.opennms.netmgt.config.charts.ImageSize)4 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1