Search in sources :

Example 16 with NumberAxis

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

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

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

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

Example 20 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatMapLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (EMDataSet ds : dataSets) dataset.addValue(1, options.getData().toString(), ds.getName());
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.HORIZONTAL, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 20.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(true);
    domainAxis.setAxisLineVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    domainAxis.setTickLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 15.0));
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    List<Color> itemColors = new ArrayList<>();
    int total = dataSets.size();
    int v = total / 2;
    for (int i = 0; i < total; i++) itemColors.add(ColorUtil.getColor(v--, -total, total, colors.get(2), colors.get(1), colors.get(0)));
    final BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(int row, int column) {
            return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
        }
    };
    plot.setRenderer(renderer);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(0.0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ArrayList(java.util.ArrayList) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)26 JFreeChart (org.jfree.chart.JFreeChart)21 CategoryAxis (org.jfree.chart.axis.CategoryAxis)12 CategoryPlot (org.jfree.chart.plot.CategoryPlot)11 XYPlot (org.jfree.chart.plot.XYPlot)10 RectangleInsets (org.jfree.ui.RectangleInsets)10 DateAxis (org.jfree.chart.axis.DateAxis)9 Color (java.awt.Color)6 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)6 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)6 Paint (java.awt.Paint)5 CategoryDataset (org.jfree.data.category.CategoryDataset)5 BasicStroke (java.awt.BasicStroke)4 Font (java.awt.Font)4 LocalDate (java.time.LocalDate)4 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)4 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3