Search in sources :

Example 16 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project watchdog by TestRoots.

the class WatchDogView method createJunitExecutionBarDataset.

private CategoryDataset createJunitExecutionBarDataset() {
    double differenceSeconds = Math.abs(averageTestDurationSeconds - junitRunsCount);
    double differenceMinutes = Math.abs(averageTestDurationMinutes - junitRunsCount);
    String testDurationTitle = "Test Run Duration";
    double testDuration;
    if (differenceSeconds < differenceMinutes) {
        testDuration = averageTestDurationSeconds;
        testDurationTitle += " (in seconds)";
    } else {
        testDuration = averageTestDurationMinutes;
        testDurationTitle += " (in minutes)";
    }
    String[] columns = new String[] { "Successful", "Failed", "Both" };
    String[] rows = new String[] { "Test Runs", testDurationTitle };
    double[][] data = new double[][] { { junitSuccessCount, 0 }, { junitFailuresCount, 0 }, { 0, testDuration } };
    CategoryDataset dataSet = DatasetUtilities.createCategoryDataset(columns, rows, data);
    return dataSet;
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) GanttCategoryDataset(org.jfree.data.gantt.GanttCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset)

Example 17 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project hudson-2.x by hudson.

the class Job method getBuildTimeGraph.

public Graph getBuildTimeGraph() {
    return new Graph(getLastBuild().getTimestamp(), 500, 400) {

        @Override
        protected JFreeChart createGraph() {
            class ChartLabel implements Comparable<ChartLabel> {

                final Run run;

                public ChartLabel(Run r) {
                    this.run = r;
                }

                public int compareTo(ChartLabel that) {
                    return Run.ORDER_BY_DATE.compare(that.run, run);
                }

                @Override
                public boolean equals(Object o) {
                    // on (c instanceof ChartLabel)
                    if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) {
                        return false;
                    }
                    ChartLabel that = (ChartLabel) o;
                    return run == that.run;
                }

                public Color getColor() {
                    // TODO: consider gradation. See
                    // http://www.javadrive.jp/java2d/shape/index9.html
                    Result r = run.getResult();
                    if (r == Result.FAILURE)
                        return ColorPalette.RED;
                    else if (r == Result.UNSTABLE)
                        return ColorPalette.YELLOW;
                    else if (r == Result.ABORTED || r == Result.NOT_BUILT)
                        return ColorPalette.GREY;
                    else
                        return ColorPalette.BLUE;
                }

                @Override
                public int hashCode() {
                    return run.hashCode();
                }

                @Override
                public String toString() {
                    String l = run.getDisplayName();
                    if (run instanceof Build) {
                        String s = ((Build) run).getBuiltOnStr();
                        if (s != null)
                            l += ' ' + s;
                    }
                    return l;
                }
            }
            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
            for (Run r : getBuilds()) {
                if (r.isBuilding())
                    continue;
                data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
            }
            final CategoryDataset dataset = data.build();
            final JFreeChart chart = // chart
            ChartFactory.createStackedAreaChart(// chart
            null, // unused
            null, // range axis label
            Messages.Job_minutes(), // data
            dataset, // orientation
            PlotOrientation.VERTICAL, // include legend
            false, // tooltips
            true, // urls
            false);
            chart.setBackgroundPaint(Color.white);
            final CategoryPlot plot = chart.getCategoryPlot();
            // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(0.8f);
            // plot.setDomainGridlinesVisible(true);
            // plot.setDomainGridlinePaint(Color.white);
            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();
            ChartUtil.adjustChebyshev(dataset, rangeAxis);
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            StackedAreaRenderer ar = new StackedAreaRenderer2() {

                @Override
                public Paint getItemPaint(int row, int column) {
                    ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
                    return key.getColor();
                }

                @Override
                public String generateURL(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return String.valueOf(label.run.number);
                }

                @Override
                public String generateToolTip(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return label.run.getDisplayName() + " : " + label.run.getDurationString();
                }
            };
            plot.setRenderer(ar);
            // crop extra space around the graph
            plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
            return chart;
        }
    };
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DataSetBuilder(hudson.util.DataSetBuilder) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) Graph(hudson.util.Graph) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JSONObject(net.sf.json.JSONObject)

Example 18 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project dhis2-core by dhis2.

the class DefaultChartService method getCategoryDataSet.

private CategoryDataset[] getCategoryDataSet(PlotData plotData) {
    Map<String, Object> valueMap;
    if (plotData.isAggregate()) {
        valueMap = analyticsService.getAggregatedDataValueMapping(plotData.getVisualization());
    } else {
        if (plotData.getEventChart() != null) {
            Grid grid = eventAnalyticsService.getAggregatedEventData(plotData.getEventChart());
            plotData.getEventChart().setDataItemGrid(grid);
            valueMap = GridUtils.getMetaValueMapping(grid, (grid.getWidth() - 1));
        } else {
            Grid grid = eventAnalyticsService.getAggregatedEventData(plotData.getEventVisualization());
            plotData.getEventVisualization().setDataItemGrid(grid);
            valueMap = GridUtils.getMetaValueMapping(grid, (grid.getWidth() - 1));
        }
    }
    DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
    DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
    SimpleRegression regression = new SimpleRegression();
    valueMap = DimensionalObjectUtils.getSortedKeysMap(valueMap);
    List<NameableObject> seriez = new ArrayList<>(plotData.series());
    List<NameableObject> categories = new ArrayList<>(defaultIfNull(plotData.category(), emptyList()));
    if (plotData.hasSortOrder()) {
        categories = getSortedCategories(categories, plotData, valueMap);
    }
    for (NameableObject series : seriez) {
        double categoryIndex = 0;
        for (NameableObject category : categories) {
            categoryIndex++;
            String key = getKey(series, category, plotData.getAnalyticsType());
            Object object = valueMap.get(key);
            Number value = object != null && object instanceof Number ? (Number) object : null;
            regularDataSet.addValue(value, series.getShortName(), category.getShortName());
            if (plotData.isRegression() && value != null && value instanceof Double && !MathUtils.isEqual((Double) value, MathUtils.ZERO)) {
                regression.addData(categoryIndex, (Double) value);
            }
        }
        if (// Period must be category
        plotData.isRegression()) {
            categoryIndex = 0;
            for (NameableObject category : plotData.category()) {
                final double value = regression.predict(categoryIndex++);
                if (!Double.isNaN(value)) {
                    regressionDataSet.addValue(value, TREND_PREFIX + series.getShortName(), category.getShortName());
                }
            }
        }
    }
    return new CategoryDataset[] { regularDataSet, regressionDataSet };
}
Also used : Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) SimpleRegression(org.apache.commons.math3.stat.regression.SimpleRegression) NameableObject(org.hisp.dhis.common.NameableObject) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) DimensionalObject(org.hisp.dhis.common.DimensionalObject) NameableObject(org.hisp.dhis.common.NameableObject) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 19 with CategoryDataset

use of org.jfree.data.category.CategoryDataset 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 20 with CategoryDataset

use of org.jfree.data.category.CategoryDataset 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

CategoryDataset (org.jfree.data.category.CategoryDataset)107 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)41 CategoryAxis (org.jfree.chart.axis.CategoryAxis)35 CategoryPlot (org.jfree.chart.plot.CategoryPlot)29 Test (org.junit.Test)29 Paint (java.awt.Paint)28 NumberAxis (org.jfree.chart.axis.NumberAxis)21 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)20 JFreeChart (org.jfree.chart.JFreeChart)17 ValueAxis (org.jfree.chart.axis.ValueAxis)17 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)16 Range (org.jfree.data.Range)13 PlotOrientation (org.jfree.chart.plot.PlotOrientation)11 DefaultCategoryItemRenderer (org.jfree.chart.renderer.category.DefaultCategoryItemRenderer)11 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)9 DefaultMultiValueCategoryDataset (org.jfree.data.statistics.DefaultMultiValueCategoryDataset)9 MultiValueCategoryDataset (org.jfree.data.statistics.MultiValueCategoryDataset)9 LegendItem (org.jfree.chart.LegendItem)8 DefaultIntervalCategoryDataset (org.jfree.data.category.DefaultIntervalCategoryDataset)8 DefaultStatisticalCategoryDataset (org.jfree.data.statistics.DefaultStatisticalCategoryDataset)8