Search in sources :

Example 11 with CategoryPlot

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

Example 12 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project hudson-2.x by hudson.

the class AbstractTestResultAction method createChart.

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {
    final String relPath = getRelPath(req);
    final JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //        legend.setAnchor(StandardLegend.SOUTH);
    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();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return relPath + label.build.getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.build.getAction(AbstractTestResultAction.class);
            switch(row) {
                case 0:
                    return String.valueOf(Messages.AbstractTestResultAction_fail(label.build.getDisplayName(), a.getFailCount()));
                case 1:
                    return String.valueOf(Messages.AbstractTestResultAction_skip(label.build.getDisplayName(), a.getSkipCount()));
                default:
                    return String.valueOf(Messages.AbstractTestResultAction_test(label.build.getDisplayName(), a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    // Failures.
    ar.setSeriesPaint(0, ColorPalette.RED);
    // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW);
    // Total.
    ar.setSeriesPaint(2, ColorPalette.BLUE);
    // 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) NumberOnlyBuildLabel(hudson.util.ChartUtil.NumberOnlyBuildLabel) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 13 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project gephi by gephi.

the class ChartsUtils method buildBoxPlot.

/**
     * Build a new box-plot from an array of numbers using a default title and yLabel.
     * String dataName will be used for xLabel.
     * @param numbers Numbers for building box-plot
     * @param dataName Name of the numbers data
     * @return Prepared box-plot
     */
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    final ArrayList<Number> list = new ArrayList<>();
    list.addAll(Arrays.asList(numbers));
    final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
    dataset.add(list, valuesString, "");
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMeanVisible(false);
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.5);
    final CategoryAxis xAxis = new CategoryAxis(dataName);
    final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
    yAxis.setAutoRangeIncludesZero(false);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setRenderer(renderer);
    JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
    return boxPlot;
}
Also used : BoxAndWhiskerRenderer(org.jfree.chart.renderer.category.BoxAndWhiskerRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) BoxAndWhiskerToolTipGenerator(org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ArrayList(java.util.ArrayList) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 14 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project hudson-2.x by hudson.

the class LoadStatistics method createChart.

/**
     * Creates a trend chart.
     */
public JFreeChart createChart(CategoryDataset ds) {
    final JFreeChart chart = // chart title
    ChartFactory.createLineChart(// chart title
    null, // unused
    null, // range axis label
    null, // data
    ds, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(3));
    configureRenderer(renderer);
    final CategoryAxis domainAxis = new NoOverlapCategoryAxis(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());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
    return chart;
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) NoOverlapCategoryAxis(hudson.util.NoOverlapCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) NoOverlapCategoryAxis(hudson.util.NoOverlapCategoryAxis)

Example 15 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project ice by Netflix.

the class BasicWeeklyCostEmailService method createImage.

private File createImage(ApplicationGroup appgroup) throws IOException {
    Map<String, Double> costs = Maps.newHashMap();
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    Interval interval = new Interval(end.minusWeeks(numWeeks), end);
    for (Product product : products) {
        List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
        if (resourceGroups.size() == 0) {
            continue;
        }
        DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
        if (dataManager == null) {
            continue;
        }
        TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups);
        Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false);
        for (Tag tag : data.keySet()) {
            for (int week = 0; week < numWeeks; week++) {
                String key = tag + "|" + week;
                if (costs.containsKey(key))
                    costs.put(key, data.get(tag)[week] + costs.get(key));
                else
                    costs.put(key, data.get(tag)[week]);
            }
        }
    }
    boolean hasData = false;
    for (Map.Entry<String, Double> entry : costs.entrySet()) {
        if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
            hasData = true;
            break;
        }
    }
    if (!hasData)
        return null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Product product : products) {
        for (int week = 0; week < numWeeks; week++) {
            String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
            dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
        }
    }
    JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
    renderer.setItemLabelAnchorOffset(10.0);
    TextTitle title = chart.getTitle();
    title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {

        public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            return costFormatter.format(dataset.getValue(row, column));
        }
    });
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(costFormatter);
    BufferedImage image = chart.createBufferedImage(1200, 400);
    File outputfile = File.createTempFile("awscost", "png");
    ImageIO.write(image, "png", outputfile);
    return outputfile;
}
Also used : StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) DateTime(org.joda.time.DateTime) BufferedImage(java.awt.image.BufferedImage) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) TextTitle(org.jfree.chart.title.TextTitle) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) File(java.io.File) Interval(org.joda.time.Interval)

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)22 JFreeChart (org.jfree.chart.JFreeChart)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)15 NumberAxis (org.jfree.chart.axis.NumberAxis)11 RectangleInsets (org.jfree.ui.RectangleInsets)9 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)8 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)7 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)7 Paint (java.awt.Paint)6 Color (java.awt.Color)5 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)3 ArrayList (java.util.ArrayList)3 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)3 StackedAreaRenderer2 (hudson.util.StackedAreaRenderer2)2 BasicStroke (java.awt.BasicStroke)2 Font (java.awt.Font)2 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)2 LogarithmicAxis (org.jfree.chart.axis.LogarithmicAxis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)2