Search in sources :

Example 76 with JFreeChart

use of org.jfree.chart.JFreeChart in project processdash by dtuma.

the class EVXYChartPanel method adjustStyle.

private void adjustStyle(int width) {
    int style;
    if (width > medium_window_width)
        style = FULL;
    else if (width > short_window_width)
        style = MED;
    else
        style = SHORT;
    JFreeChart chart = getChart();
    chart.removeLegend();
    if (style == FULL)
        chart.addLegend(legend);
    adjustAxis(chart.getXYPlot().getRangeAxis(), style != FULL, yLabel);
    adjustAxis(chart.getXYPlot().getDomainAxis(), style == SHORT, xLabel);
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Example 77 with JFreeChart

use of org.jfree.chart.JFreeChart in project processdash by dtuma.

the class EstErrorScatterChart method createChart.

@Override
public JFreeChart createChart() {
    JFreeChart chart = super.createChart();
    // set minimum/maximum bounds on the two axes
    XYPlot xyPlot = chart.getXYPlot();
    double cutoff = getPercentParam("cut", 100, 200, 5000);
    xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff));
    xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff));
    xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer()));
    // add a box illustrating the target range
    if (data.numRows() > 0) {
        double box = getPercentParam("pct", 0, 50, 100);
        xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box));
        xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0));
        xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box));
    }
    return chart;
}
Also used : XYBoxAnnotation(org.jfree.chart.annotations.XYBoxAnnotation) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAnnotation(org.jfree.chart.annotations.XYLineAnnotation) JFreeChart(org.jfree.chart.JFreeChart)

Example 78 with JFreeChart

use of org.jfree.chart.JFreeChart in project processdash by dtuma.

the class XYChart method createChart.

/** Create a scatter plot. */
@Override
public JFreeChart createChart() {
    JFreeChart chart;
    String xLabel = null, yLabel = null;
    if (!chromeless) {
        xLabel = Translator.translate(data.getColName(1));
        yLabel = getSetting("yLabel");
        if (yLabel == null && data.numCols() == 2)
            yLabel = data.getColName(2);
        if (yLabel == null)
            yLabel = getSetting("units");
        if (yLabel == null)
            yLabel = "Value";
        yLabel = Translator.translate(yLabel);
    }
    Object autoZero = parameters.get("autoZero");
    boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData;
    if (firstColumnContainsDate || parameters.get("xDate") != null) {
        chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false);
        if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
    } else {
        XYDataset src = data.xyDataSource();
        chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false);
        if (src instanceof XYToolTipGenerator) {
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
        }
        String trendLine = getParameter("trend");
        if ("none".equalsIgnoreCase(trendLine))
            ;
        else if ("average".equalsIgnoreCase(trendLine))
            addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
        else
            addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
    }
    if (autoZero != null) {
        if (!"x".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
        if (!"y".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
    }
    if (data.numCols() == 2)
        chart.removeLegend();
    return chart;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) DateData(net.sourceforge.processdash.data.DateData) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 79 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class ChartController method getChart.

//--------------------------------------------------------------------------
// Get data
//--------------------------------------------------------------------------
@RequestMapping(value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET)
public void getChart(@PathVariable("uid") String uid, @RequestParam(value = "date", required = false) Date date, @RequestParam(value = "ou", required = false) String ou, @RequestParam(value = "width", defaultValue = "800", required = false) int width, @RequestParam(value = "height", defaultValue = "500", required = false) int height, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws IOException, WebMessageException {
    Chart chart = chartService.getChartNoAcl(uid);
    if (chart == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Chart does not exist: " + uid));
    }
    OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
    JFreeChart jFreeChart = chartService.getJFreeChart(chart, date, unit, i18nManager.getI18nFormat());
    String filename = CodecUtils.filenameEncode(chart.getName()) + ".png";
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment);
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) JFreeChart(org.jfree.chart.JFreeChart) Chart(org.hisp.dhis.chart.Chart) JFreeChart(org.jfree.chart.JFreeChart) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class ChartController method getChart.

@RequestMapping(value = { "/data", "/data.png" }, method = RequestMethod.GET)
public void getChart(@RequestParam(value = "in") String indicatorUid, @RequestParam(value = "ou") String organisationUnitUid, @RequestParam(value = "periods", required = false) boolean periods, @RequestParam(value = "width", defaultValue = "800", required = false) int width, @RequestParam(value = "height", defaultValue = "500", required = false) int height, @RequestParam(value = "skipTitle", required = false) boolean skipTitle, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws IOException {
    Indicator indicator = indicatorService.getIndicator(indicatorUid);
    OrganisationUnit unit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
    JFreeChart chart;
    if (periods) {
        chart = chartService.getJFreePeriodChart(indicator, unit, !skipTitle, i18nManager.getI18nFormat());
    } else {
        chart = chartService.getJFreeOrganisationUnitChart(indicator, unit, !skipTitle, i18nManager.getI18nFormat());
    }
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", attachment);
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Indicator(org.hisp.dhis.indicator.Indicator) JFreeChart(org.jfree.chart.JFreeChart) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10