Search in sources :

Example 6 with CategoryAxis

use of org.jfree.chart.axis.CategoryAxis 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 7 with CategoryAxis

use of org.jfree.chart.axis.CategoryAxis 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)

Example 8 with CategoryAxis

use of org.jfree.chart.axis.CategoryAxis in project processdash by dtuma.

the class CGIChartBase method setupCategoryChart.

protected void setupCategoryChart(JFreeChart chart) {
    if (!(chart.getPlot() instanceof CategoryPlot))
        return;
    CategoryPlot cp = chart.getCategoryPlot();
    CategoryAxis catAxis = cp.getDomainAxis();
    ValueAxis otherAxis = cp.getRangeAxis();
    if (!chromeless) {
        String catAxisLabel = data.getColName(0);
        if (catAxisLabel == null)
            catAxisLabel = Translator.translate("Project/Task");
        String otherAxisLabel = Translator.translate(getSetting("units"));
        if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1)
            otherAxisLabel = data.getColName(1);
        if (otherAxisLabel == null)
            otherAxisLabel = Translator.translate("Value");
        String catLabels = getParameter("categoryLabels");
        catAxis.setLabel(catAxisLabel);
        otherAxis.setLabel(otherAxisLabel);
        if ("vertical".equalsIgnoreCase(catLabels))
            catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        else if ("none".equalsIgnoreCase(catLabels))
            catAxis.setTickLabelsVisible(false);
    }
    if (data.numCols() == 1 && getParameter("noSkipLegend") == null) {
        chart.removeLegend();
        chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5));
    }
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.ui.RectangleInsets) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 9 with CategoryAxis

use of org.jfree.chart.axis.CategoryAxis 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)

Example 10 with CategoryAxis

use of org.jfree.chart.axis.CategoryAxis in project violations-plugin by jenkinsci.

the class AbstractViolationsBuildAction method createChart.

// FIXME this should be in a utility class
protected JFreeChart createChart(CategoryDataset dataset) {
    final JFreeChart chart = // chart
    ChartFactory.createLineChart(// 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();
    if (useLog) {
        final NumberAxis rangeAxis2 = new LogarithmicAxis("Log(y)");
        plot.setRangeAxis(rangeAxis2);
    }
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    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());
    // rangeAxis.setUpperBound(100);
    if (Boolean.getBoolean(VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    } else {
        rangeAxis.setLowerBound(0);
    }
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(PADDING, 0, 0, PADDING));
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Aggregations

CategoryAxis (org.jfree.chart.axis.CategoryAxis)19 JFreeChart (org.jfree.chart.JFreeChart)15 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 NumberAxis (org.jfree.chart.axis.NumberAxis)12 RectangleInsets (org.jfree.ui.RectangleInsets)8 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)5 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)5 Paint (java.awt.Paint)4 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)4 CategoryDataset (org.jfree.data.category.CategoryDataset)4 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)3 Color (java.awt.Color)3 ArrayList (java.util.ArrayList)3 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)3 StackedAreaRenderer2 (hudson.util.StackedAreaRenderer2)2 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)2 LogarithmicAxis (org.jfree.chart.axis.LogarithmicAxis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)2