use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.
the class ChartResult method execute.
/**
* Executes the result. Writes the given chart as a PNG to the servlet
* output stream.
*
* @param invocation an encapsulation of the action execution state.
* @throws Exception if an error occurs when creating or writing the chart
* to the servlet output stream.
*/
@Override
public void execute(ActionInvocation invocation) throws Exception {
JFreeChart stackChart = (JFreeChart) invocation.getStack().findValue("chart");
chart = stackChart != null ? stackChart : chart;
Integer stackHeight = (Integer) invocation.getStack().findValue("height");
height = stackHeight != null && stackHeight > 0 ? stackHeight : height != null ? height : DEFAULT_HEIGHT;
Integer stackWidth = (Integer) invocation.getStack().findValue("width");
width = stackWidth != null && stackWidth > 0 ? stackWidth : width != null ? width : DEFAULT_WIDTH;
String stackFilename = (String) invocation.getStack().findValue("filename");
filename = StringUtils.defaultIfEmpty(stackFilename, DEFAULT_FILENAME);
if (chart == null) {
log.warn("No chart found");
return;
}
HttpServletResponse response = ServletActionContext.getResponse();
ContextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, true, filename, false);
OutputStream os = response.getOutputStream();
ChartUtilities.writeChartAsPNG(os, chart, width, height);
os.flush();
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class TimeLogPhaseWaterfallChart method createChart.
private JFreeChart createChart(IntervalXYDataset dataset, ProcessUtil process, List<String> phases, GapSkipTracker gaps) {
JFreeChart result = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL, false, true, false);
XYPlot xyplot = (XYPlot) result.getPlot();
DateAxis dateAxis = new DateAxis(null);
dateAxis.setTickMarksVisible(false);
dateAxis.setTickLabelsVisible(false);
dateAxis.setLowerMargin(0.01);
dateAxis.setUpperMargin(0.01);
setupGaps(gaps, dateAxis, xyplot);
xyplot.setDomainAxis(dateAxis);
String[] phaseNameList = new String[phases.size()];
for (int i = 0; i < phaseNameList.length; i++) phaseNameList[i] = Translator.translate(phases.get(i));
SymbolAxis symbolaxis = new SymbolAxis(null, phaseNameList);
symbolaxis.setGridBandsVisible(false);
xyplot.setRangeAxis(symbolaxis);
final XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer();
renderer.setUseYInterval(true);
renderer.setDrawBarOutline(true);
renderer.setBaseOutlinePaint(Color.black);
new PhaseChartColorer(process, phases) {
public void setItemColor(Object key, int pos, Color c) {
renderer.setSeriesPaint(pos, c);
}
}.run();
int exceptionSeries = dataset.getSeriesCount() - 1;
renderer.setSeriesPaint(exceptionSeries, EXCEPTION_PAINT);
renderer.setSeriesFillPaint(exceptionSeries, EXCEPTION_PAINT);
renderer.setSeriesOutlinePaint(exceptionSeries, EXCEPTION_PAINT);
renderer.setBaseToolTipGenerator(new TooltipGenerator());
xyplot.setBackgroundPaint(Color.white);
xyplot.setDomainGridlinesVisible(false);
xyplot.setRangeGridlinePaint(Color.lightGray);
xyplot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
result.setAntiAlias(false);
result.setTextAntiAlias(true);
parameters.put("title", resources.getString("Title"));
return result;
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class BarChart method createChart.
/** Create a bar chart. */
public JFreeChart createChart() {
//if (data.numCols() == 1) data = data.transpose();
JFreeChart chart;
// default
boolean vertical = true;
String direction = getParameter("dir");
if ((direction != null && direction.toLowerCase().startsWith("hor")) || parameters.get("horizontal") != null)
vertical = false;
chart = ChartFactory.createBarChart3D(null, null, null, data.catDataSource(), (vertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL), true, true, false);
setupCategoryChart(chart);
return chart;
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class DiscChart method createDiscChart.
public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
// data.sortBy(1, true);
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
DiscPlot plot = new DiscPlot(pieData);
plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("discLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);
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) {
}
return chart;
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class LineChart method createChart.
/** Create a line chart. */
public JFreeChart createChart() {
JFreeChart chart = ChartFactory.createLineChart(null, null, null, data.catDataSource(), PlotOrientation.VERTICAL, true, true, false);
setupCategoryChart(chart);
return chart;
}
Aggregations