Search in sources :

Example 26 with CategoryPlot

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

the class DefaultChartService method getStackedAreaChart.

private JFreeChart getStackedAreaChart(PlotData plotData, CategoryDataset dataSet) {
    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart(plotData.getName(), plotData.getDomainAxisLabel(), plotData.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !plotData.isHideLegend(), false, false);
    setBasicConfig(stackedAreaChart, plotData);
    CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRenderer(getStackedAreaRenderer());
    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    xAxis.setLabelFont(LABEL_FONT);
    return stackedAreaChart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 27 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot 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)

Example 28 with CategoryPlot

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

the class DefaultChartService method getStackedBarChart.

private JFreeChart getStackedBarChart(PlotData plotData, CategoryDataset dataSet, boolean horizontal) {
    JFreeChart stackedBarChart = ChartFactory.createStackedBarChart(plotData.getName(), plotData.getDomainAxisLabel(), plotData.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !plotData.isHideLegend(), false, false);
    setBasicConfig(stackedBarChart, plotData);
    CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot();
    plot.setOrientation(horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL);
    plot.setRenderer(getStackedBarRenderer());
    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    return stackedBarChart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 29 with CategoryPlot

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

the class DefaultChartService method getCategoryPlot.

/**
 * Returns a CategoryPlot.
 */
private CategoryPlot getCategoryPlot(CategoryDataset dataSet, CategoryItemRenderer renderer, PlotOrientation orientation, CategoryLabelPositions labelPositions) {
    CategoryPlot plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), renderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setOrientation(orientation);
    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(labelPositions);
    return plot;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 30 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project violations-plugin by jenkinsci.

the class SeverityTypeDataSet method createChart.

/**
 * Create a JFree chart for this dataset.
 *
 * @return the chart.
 */
public JFreeChart createChart() {
    CategoryDataset dataset = buildDataSet();
    JFreeChart chart = // chart
    ChartFactory.createStackedAreaChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(ALPHA);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    }
    StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, VIOLET);
    renderer.setSeriesPaint(0, YELLOW);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
    return chart;
}
Also used : ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)190 JFreeChart (org.jfree.chart.JFreeChart)94 CategoryAxis (org.jfree.chart.axis.CategoryAxis)88 NumberAxis (org.jfree.chart.axis.NumberAxis)80 Test (org.junit.Test)72 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)36 ValueAxis (org.jfree.chart.axis.ValueAxis)35 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)32 CategoryDataset (org.jfree.data.category.CategoryDataset)29 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)27 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)24 Paint (java.awt.Paint)23 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)16 LegendItem (org.jfree.chart.LegendItem)15 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)14 RectangleInsets (org.jfree.ui.RectangleInsets)13 XYPlot (org.jfree.chart.plot.XYPlot)12 ArrayList (java.util.ArrayList)11 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)11