Search in sources :

Example 1 with PlotData

use of org.hisp.dhis.visualization.PlotData in project dhis2-core by dhis2.

the class VisualizationDataController method getVisualizationData.

@GetMapping(value = { "/visualizations/{uid}/data", "/visualizations/{uid}/data.png" })
public void getVisualizationData(@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 {
    final Visualization visualization = visualizationService.getVisualizationNoAcl(uid);
    if (visualization == null) {
        throw new WebMessageException(notFound("Visualization does not exist: " + uid));
    }
    if (visualization.isChart() && isChartSupported(visualization.getType())) {
        OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
        JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(visualization), date, unit, i18nManager.getI18nFormat(), currentUserService.getCurrentUser());
        String filename = CodecUtils.filenameEncode(visualization.getName()) + ".png";
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment);
        ChartUtils.writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
    } else {
        response.setContentType(CONTENT_TYPE_JSON);
        renderService.toJson(response.getOutputStream(), getReportTableGrid(uid, ou, date));
    }
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with PlotData

use of org.hisp.dhis.visualization.PlotData in project dhis2-core by dhis2.

the class EventVisualizationController method generateChart.

@GetMapping(value = { "/{uid}/data", "/{uid}/data.png" })
void generateChart(@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 {
    // TODO no acl?
    final EventVisualization eventVisualization = eventVisualizationService.getEventVisualization(uid);
    if (eventVisualization == null) {
        throw new WebMessageException(notFound("Event visualization does not exist: " + uid));
    }
    doesNotAllowPivotAndReportChart(eventVisualization);
    final OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
    final JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(eventVisualization), date, unit, i18nManager.getI18nFormat());
    final String filename = filenameEncode(eventVisualization.getName()) + ".png";
    contextUtils.configureResponse(response, CONTENT_TYPE_PNG, RESPECT_SYSTEM_SETTING, filename, attachment);
    writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with PlotData

use of org.hisp.dhis.visualization.PlotData in project dhis2-core by dhis2.

the class EventChartController method getChart.

// --------------------------------------------------------------------------
// Get data
// --------------------------------------------------------------------------
@GetMapping(value = { "/{uid}/data", "/{uid}/data.png" })
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 {
    // TODO no
    EventChart chart = eventChartService.getEventChart(uid);
    if (chart == null) {
        throw new WebMessageException(notFound("Event chart does not exist: " + uid));
    }
    OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
    JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(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);
    ChartUtils.writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventChart(org.hisp.dhis.eventchart.EventChart) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with PlotData

use of org.hisp.dhis.visualization.PlotData in project dhis2-core by dhis2.

the class DefaultChartService method getJFreePeriodChart.

// -------------------------------------------------------------------------
// Specific chart methods
// -------------------------------------------------------------------------
@Override
@Transactional(readOnly = true)
public JFreeChart getJFreePeriodChart(Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format) {
    List<Period> periods = periodService.reloadPeriods(new RelativePeriods().setLast12Months(true).getRelativePeriods(format, true));
    Visualization visualization = new Visualization();
    if (title) {
        visualization.setName(indicator.getName());
    }
    visualization.setType(VisualizationType.LINE);
    visualization.setColumnDimensions(Arrays.asList(DimensionalObject.DATA_X_DIM_ID));
    visualization.setRowDimensions(Arrays.asList(DimensionalObject.PERIOD_DIM_ID));
    visualization.setFilterDimensions(Arrays.asList(DimensionalObject.ORGUNIT_DIM_ID));
    visualization.setHideLegend(true);
    visualization.addDataDimensionItem(indicator);
    visualization.setPeriods(periods);
    visualization.getOrganisationUnits().add(unit);
    visualization.setHideSubtitle(title);
    visualization.setFormat(format);
    return getJFreeChart(new PlotData(visualization));
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) RelativePeriods(org.hisp.dhis.period.RelativePeriods) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with PlotData

use of org.hisp.dhis.visualization.PlotData in project dhis2-core by dhis2.

the class DefaultChartService method getJFreeOrganisationUnitChart.

@Override
@Transactional(readOnly = true)
public JFreeChart getJFreeOrganisationUnitChart(Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format) {
    List<Period> periods = periodService.reloadPeriods(new RelativePeriods().setThisYear(true).getRelativePeriods(format, true));
    Visualization visualization = new Visualization();
    if (title) {
        visualization.setName(indicator.getName());
    }
    visualization.setType(VisualizationType.COLUMN);
    visualization.setColumnDimensions(Arrays.asList(DimensionalObject.DATA_X_DIM_ID));
    visualization.setRowDimensions(Arrays.asList(DimensionalObject.ORGUNIT_DIM_ID));
    visualization.setFilterDimensions(Arrays.asList(DimensionalObject.PERIOD_DIM_ID));
    visualization.setHideLegend(true);
    visualization.addDataDimensionItem(indicator);
    visualization.setPeriods(periods);
    visualization.setOrganisationUnits(parent.getSortedChildren());
    visualization.setHideSubtitle(title);
    visualization.setFormat(format);
    return getJFreeChart(new PlotData(visualization));
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) RelativePeriods(org.hisp.dhis.period.RelativePeriods) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PlotData (org.hisp.dhis.visualization.PlotData)5 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Visualization (org.hisp.dhis.visualization.Visualization)3 JFreeChart (org.jfree.chart.JFreeChart)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Period (org.hisp.dhis.period.Period)2 RelativePeriods (org.hisp.dhis.period.RelativePeriods)2 Transactional (org.springframework.transaction.annotation.Transactional)2 EventChart (org.hisp.dhis.eventchart.EventChart)1 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)1