use of org.jfree.data.general.ValueDataset in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChart.
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
private JFreeChart getJFreeChart(BaseChart chart) {
final CategoryDataset[] dataSets = getCategoryDataSet(chart);
final CategoryDataset dataSet = dataSets[0];
final BarRenderer barRenderer = getBarRenderer();
final LineAndShapeRenderer lineRenderer = getLineRenderer();
// ---------------------------------------------------------------------
// Plot
// ---------------------------------------------------------------------
CategoryPlot plot = null;
if (chart.isType(ChartType.LINE)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (chart.isType(ChartType.COLUMN)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (chart.isType(ChartType.BAR)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.HORIZONTAL);
} else if (chart.isType(ChartType.AREA)) {
return getStackedAreaChart(chart, dataSet);
} else if (chart.isType(ChartType.PIE)) {
return getMultiplePieChart(chart, dataSets);
} else if (chart.isType(ChartType.STACKED_COLUMN)) {
return getStackedBarChart(chart, dataSet, false);
} else if (chart.isType(ChartType.STACKED_BAR)) {
return getStackedBarChart(chart, dataSet, true);
} else if (chart.isType(ChartType.RADAR)) {
return getRadarChart(chart, dataSet);
} else if (chart.isType(ChartType.GAUGE)) {
Number number = dataSet.getValue(0, 0);
ValueDataset valueDataSet = new DefaultValueDataset(number);
return getGaugeChart(chart, valueDataSet);
} else {
throw new IllegalArgumentException("Illegal or no chart type: " + chart.getType());
}
if (chart.isRegression()) {
plot.setDataset(1, dataSets[1]);
plot.setRenderer(1, lineRenderer);
}
JFreeChart jFreeChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
setBasicConfig(jFreeChart, chart);
if (chart.isTargetLine()) {
plot.addRangeMarker(getMarker(chart.getTargetLineValue(), chart.getTargetLineLabel()));
}
if (chart.isBaseLine()) {
plot.addRangeMarker(getMarker(chart.getBaseLineValue(), chart.getBaseLineLabel()));
}
if (chart.isHideSubtitle()) {
jFreeChart.addSubtitle(getSubTitle(chart));
}
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
// ---------------------------------------------------------------------
// Category label positions
// ---------------------------------------------------------------------
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
domainAxis.setLabel(chart.getDomainAxisLabel());
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabel(chart.getRangeAxisLabel());
return jFreeChart;
}
use of org.jfree.data.general.ValueDataset in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChart.
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
private JFreeChart getJFreeChart(PlotData plotData) {
final CategoryDataset[] dataSets = getCategoryDataSet(plotData);
final CategoryDataset dataSet = dataSets[0];
final BarRenderer barRenderer = getBarRenderer();
final LineAndShapeRenderer lineRenderer = getLineRenderer();
// ---------------------------------------------------------------------
// Plot
// ---------------------------------------------------------------------
CategoryPlot plot;
if (plotData.isType(VisualizationType.LINE.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (plotData.isType(VisualizationType.COLUMN.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (plotData.isType(VisualizationType.BAR.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.HORIZONTAL);
} else if (plotData.isType(VisualizationType.AREA.name())) {
return getStackedAreaChart(plotData, dataSet);
} else if (plotData.isType(VisualizationType.PIE.name())) {
return getMultiplePieChart(plotData, dataSets);
} else if (plotData.isType(VisualizationType.STACKED_COLUMN.name())) {
return getStackedBarChart(plotData, dataSet, false);
} else if (plotData.isType(VisualizationType.STACKED_BAR.name())) {
return getStackedBarChart(plotData, dataSet, true);
} else if (plotData.isType(VisualizationType.RADAR.name())) {
return getRadarChart(plotData, dataSet);
} else if (plotData.isType(VisualizationType.GAUGE.name())) {
Number number = dataSet.getValue(0, 0);
ValueDataset valueDataSet = new DefaultValueDataset(number);
return getGaugeChart(plotData, valueDataSet);
} else {
throw new IllegalArgumentException("Illegal or no chart type: " + plotData.getType());
}
if (plotData.isRegression()) {
plot.setDataset(1, dataSets[1]);
plot.setRenderer(1, lineRenderer);
}
JFreeChart jFreeChart = new JFreeChart(plotData.getName(), TITLE_FONT, plot, !plotData.isHideLegend());
setBasicConfig(jFreeChart, plotData);
if (plotData.isTargetLine()) {
plot.addRangeMarker(getMarker(plotData.getTargetLineValue(), plotData.getTargetLineLabel()));
}
if (plotData.isBaseLine()) {
plot.addRangeMarker(getMarker(plotData.getBaseLineValue(), plotData.getBaseLineLabel()));
}
if (plotData.isHideSubtitle()) {
jFreeChart.addSubtitle(getSubTitle(plotData));
}
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
// ---------------------------------------------------------------------
// Category label positions
// ---------------------------------------------------------------------
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
domainAxis.setLabel(plotData.getDomainAxisLabel());
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabel(plotData.getRangeAxisLabel());
return jFreeChart;
}
Aggregations