use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class PieChart method createChart.
/** Create a line chart. */
@Override
public JFreeChart createChart() {
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
JFreeChart chart = null;
if (get3DSetting()) {
chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
chart.getPlot().setForegroundAlpha(ALPHA);
} else {
chart = ChartFactory.createPieChart(null, pieData, true, true, false);
}
PiePlot plot = (PiePlot) chart.getPlot();
if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("wedgeLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
plot.setCircular(true);
else
plot.setCircular(false);
Object colorScheme = parameters.get("colorScheme");
if ("byPhase".equals(colorScheme))
maybeConfigurePhaseColors(plot, pieData);
else if ("consistent".equals(colorScheme))
// since 2.0.9
configureConsistentColors(plot, pieData);
else if (parameters.containsKey("c1"))
configureIndividualColors(plot, pieData);
String interiorGap = (String) parameters.get("interiorGap");
if (interiorGap != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
} catch (NumberFormatException e) {
}
String interiorSpacing = (String) parameters.get("interiorSpacing");
if (interiorSpacing != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
} catch (NumberFormatException e) {
}
if (!parameters.containsKey("showZeroValues")) {
plot.setIgnoreZeroValues(true);
plot.setIgnoreNullValues(true);
}
return chart;
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class CGIChartBase method writeContents.
/** Generate CGI chart output. */
@Override
protected void writeContents() throws IOException {
// get the data for display
buildData();
chromeless = (parameters.get("chromeless") != null);
JFreeChart chart = createChart();
int width = getIntSetting("width");
int height = getIntSetting("height");
Color initGradColor = getColorSetting("initGradColor");
Color finalGradColor = getColorSetting("finalGradColor");
chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
if (parameters.get("hideOutline") != null)
chart.getPlot().setOutlinePaint(INVISIBLE);
String title = getSetting("title");
if (chromeless || title == null || title.length() == 0)
chart.setTitle((TextTitle) null);
else {
chart.setTitle(Translator.translate(title));
String titleFontSize = getSetting("titleFontSize");
if (titleFontSize != null)
try {
float fontSize = Float.parseFloat(titleFontSize);
TextTitle t = chart.getTitle();
t.setFont(t.getFont().deriveFont(fontSize));
} catch (Exception tfe) {
}
}
if (chromeless || parameters.get("hideLegend") != null)
chart.removeLegend();
else {
LegendTitle l = chart.getLegend();
String legendFontSize = getSetting("legendFontSize");
if (l != null && legendFontSize != null)
try {
float fontSize = Float.parseFloat(legendFontSize);
l.setItemFont(l.getItemFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
}
chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));
Axis xAxis = getHorizontalAxis(chart);
if (xAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
xAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) {
String tfs = getParameter("xTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
}
}
Axis yAxis = getVerticalAxis(chart);
if (yAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
yAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) {
String tfs = getParameter("yTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
}
}
String axisFontSize = getSetting("axisLabelFontSize");
if (axisFontSize != null)
try {
float fontSize = Float.parseFloat(axisFontSize);
if (xAxis != null)
xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
if (yAxis != null)
yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
} catch (Exception afs) {
}
ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = img.createGraphics();
if ("auto".equals(getSetting("titleFontSize")))
maybeAdjustTitleFontSize(chart, g2, width);
chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
g2.dispose();
String outputFormat = getSetting("outputFormat");
OutputStream imgOut;
if (isHtmlMode()) {
imgOut = PngCache.getOutputStream();
} else {
imgOut = outStream;
}
ImageIO.write(img, outputFormat, imgOut);
imgOut.flush();
imgOut.close();
if (isHtmlMode())
writeImageHtml(width, height, imgOut.hashCode(), info);
}
use of org.jfree.chart.JFreeChart 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.jfree.chart.JFreeChart 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.jfree.chart.JFreeChart 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));
}
Aggregations