use of org.jfree.chart.JFreeChart 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.jfree.chart.JFreeChart in project violations-plugin by jenkinsci.
the class SeverityTypeDataSet method createChart.
/**
* Create a JFree chart for this dataset.
*
* @return the chart.
*/
public JFreeChart createChart() {
CategoryDataset dataset = buildDataSet();
JFreeChart chart = // chart
ChartFactory.createStackedAreaChart(// chart
null, // unused
null, // range axis label
"count", // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(ALPHA);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setAutoRangeMinimumSize(50);
}
StackedAreaRenderer renderer = new StackedAreaRenderer2();
plot.setRenderer(renderer);
renderer.setSeriesPaint(2, RED);
renderer.setSeriesPaint(1, VIOLET);
renderer.setSeriesPaint(0, YELLOW);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
return chart;
}
use of org.jfree.chart.JFreeChart in project n2a by frothga.
the class Plot method createGraphPanel.
public JPanel createGraphPanel() {
XYDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
return new ChartPanelDrag(chart);
}
use of org.jfree.chart.JFreeChart in project EnrichmentMapApp by BaderLab.
the class RadialHeatMapLayer method createChart.
@Override
protected JFreeChart createChart(final PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(// chart title
null, // data
dataset, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final PiePlot plot = (PiePlot) chart.getPlot();
plot.setCircular(true);
plot.setStartAngle(startAngle);
plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setInteriorGap(INTERIOR_GAP);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setShadowPaint(TRANSPARENT_COLOR);
plot.setShadowXOffset(0.0);
plot.setShadowYOffset(0.0);
plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
plot.setSimpleLabels(true);
plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
plot.setLabelShadowPaint(TRANSPARENT_COLOR);
plot.setLabelPaint(labelColor);
final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
Color upperColor = Color.BLUE;
Color zeroColor = Color.WHITE;
Color lowerColor = Color.RED;
Color nanColor = DEFAULT_ITEM_BG_COLOR;
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
final int colorsSize = colors != null ? colors.size() : 0;
if (colorsSize > 0)
upperColor = colors.get(0);
if (colorsSize > 1)
zeroColor = colors.get(1);
if (colorsSize > 2)
lowerColor = colors.get(2);
if (colorsSize > 3)
nanColor = colors.get(3);
}
final List<?> keys = dataset.getKeys();
final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
for (int i = 0; i < keys.size(); i++) {
String k = (String) keys.get(i);
Double v = values.size() > i ? values.get(i) : null;
final Color c;
if (v == null)
c = nanColor;
else
c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
plot.setSectionPaint(k, c);
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
plot.setSectionOutlineStroke(k, stroke);
}
return chart;
}
use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.
the class ChartController method getHistoryChart.
@RequestMapping(value = { "/history/data", "/history/data.png" }, method = RequestMethod.GET)
public void getHistoryChart(@RequestParam String de, @RequestParam String co, @RequestParam String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(defaultValue = "525", required = false) int width, @RequestParam(defaultValue = "300", required = false) int height, HttpServletResponse response) throws IOException, WebMessageException {
DataElement dataElement = dataElementService.getDataElement(de);
if (dataElement == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data element does not exist: " + de));
}
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(co);
if (categoryOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + co));
}
DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo(cp);
if (attributeOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + cp));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period does not exist: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist: " + ou));
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", false);
JFreeChart chart = chartService.getJFreeChartHistory(dataElement, categoryOptionCombo, attributeOptionCombo, period, organisationUnit, 13, i18nManager.getI18nFormat());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}
Aggregations