Search in sources :

Example 1 with ValueDataset

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;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 2 with ValueDataset

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;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 DefaultValueDataset (org.jfree.data.general.DefaultValueDataset)2 ValueDataset (org.jfree.data.general.ValueDataset)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)1 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)1 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)1