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));
}
}
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);
}
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);
}
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));
}
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));
}
Aggregations