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);
}
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;
}
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);
}
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));
}
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;
}
Aggregations