Search in sources :

Example 1 with BarChart

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

the class ChartUtils method getChartAsBufferedImage.

/**
     * Helper method used to return a JFreeChart as a buffered Image.
     *
     * @param chartName a {@link java.lang.String} object.
     * @return a <code>BufferedImage</code>
     * @throws java.io.IOException if any.
     * @throws java.sql.SQLException if any.
     */
public static BufferedImage getChartAsBufferedImage(String chartName) throws IOException, SQLException {
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    ImageSize imageSize = chartConfig.getImageSize();
    int hzPixels;
    int vtPixels;
    if (imageSize == null) {
        hzPixels = 400;
        vtPixels = 400;
    } else {
        hzPixels = imageSize.getHzSize().getPixels();
        vtPixels = imageSize.getVtSize().getPixels();
    }
    return chart.createBufferedImage(hzPixels, vtPixels);
}
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)

Example 2 with BarChart

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

the class ChartUtils method getBarChart.

/**
     * This method will returns a JFreeChart bar chart constructed based on XML configuration.
     *
     * @param chartName Name specified in chart-configuration.xml
     * @return <code>JFreeChart</code> constructed from the chartName
     * @throws java.io.IOException if any.
     * @throws java.sql.SQLException if any.
     */
public static JFreeChart getBarChart(String chartName) throws IOException, SQLException {
    //ChartConfigFactory.reload();
    BarChart chartConfig = null;
    chartConfig = getBarChartConfigByName(chartName);
    if (chartConfig == null) {
        throw new IllegalArgumentException("getBarChart: Invalid chart name.");
    }
    DefaultCategoryDataset baseDataSet = buildCategoryDataSet(chartConfig);
    JFreeChart barChart = createBarChart(chartConfig, baseDataSet);
    addSubTitles(chartConfig, barChart);
    if (chartConfig.getSubLabelClass().isPresent()) {
        addSubLabels(barChart, chartConfig.getSubLabelClass().get());
    }
    customizeSeries(barChart, chartConfig);
    return barChart;
}
Also used : BarChart(org.opennms.netmgt.config.charts.BarChart) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with BarChart

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

the class ChartUtils method getBarChart.

/**
     * 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 getBarChart(String chartName, OutputStream out) throws IOException, SQLException {
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    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.writeChartAsJPEG(out, chart, hzPixels, vtPixels);
}
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)

Example 4 with BarChart

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

the class ChartUtils method getBarChartAsPNGByteArray.

/**
     * Helper method that returns the JFreeChart as a PNG byte array.
     *
     * @param chartName a {@link java.lang.String} object.
     * @return a byte array
     * @throws java.io.IOException if any.
     * @throws java.sql.SQLException if any.
     */
public static byte[] getBarChartAsPNGByteArray(String chartName) throws IOException, SQLException {
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    ImageSize imageSize = chartConfig.getImageSize();
    int hzPixels;
    int vtPixels;
    if (imageSize == null) {
        hzPixels = 400;
        vtPixels = 400;
    } else {
        hzPixels = imageSize.getHzSize().getPixels();
        vtPixels = imageSize.getVtSize().getPixels();
    }
    return ChartUtilities.encodeAsPNG(chart.createBufferedImage(hzPixels, vtPixels));
}
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)

Example 5 with BarChart

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

the class ChartUtils method getBarChartConfigByName.

/**
     * Helper method used to retrieve the XML defined BarChart
     *
     * @param chartName a {@link java.lang.String} object.
     * @return a BarChart
     * @throws java.io.IOException if any.
     */
public static BarChart getBarChartConfigByName(String chartName) throws IOException {
    Iterator<BarChart> it = getChartCollectionIterator();
    BarChart chart = null;
    while (it.hasNext()) {
        chart = (BarChart) it.next();
        if (chart.getName().equals(chartName))
            return chart;
    }
    return null;
}
Also used : BarChart(org.opennms.netmgt.config.charts.BarChart)

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