Search in sources :

Example 1 with BarRenderer3D

use of org.jfree.chart.renderer.category.BarRenderer3D in project pentaho-platform by pentaho.

the class JFreeChartEngine method createBarChart.

private static JFreeChart createBarChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    PlotOrientation orientation = chartDefinition.getOrientation();
    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    BarRenderer renderer = null;
    // Determine the type of renderer to use
    if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
        if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
            renderer = new StackedBarRenderer3D();
        } else if (chartDefinition.isStacked()) {
            renderer = new StackedBarRenderer();
        } else {
            renderer = new BarRenderer3D();
        }
    } else {
        renderer = new BarRenderer();
    }
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
        renderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
        renderer.setNegativeItemLabelPosition(position2);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
        renderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
        renderer.setNegativeItemLabelPosition(position2);
    }
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }
    if (chartDefinition.getMaxBarWidth() != null) {
        renderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
    }
    CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberAxis(org.jfree.chart.axis.NumberAxis) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Example 2 with BarRenderer3D

use of org.jfree.chart.renderer.category.BarRenderer3D in project adempiere by adempiere.

the class CRPDetail method createChart.

/**
	 * Create Chart based on UOM
	 * 
	 * @param dataset
	 * @param title
	 * @param uom
	 * @return JFreeChart Chart based On UOM
	 */
public JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {
    JFreeChart chart = ChartFactory.createBarChart3D(title, // X-Axis label
    Msg.translate(Env.getCtx(), "Day"), Msg.translate(Env.getCtx(), // Y-Axis
    (uom == null) ? "" : uom.getName()), // Dataset
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips?
    true, // URLs?
    false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.GRAY);
    BarRenderer3D barrenderer = (BarRenderer3D) plot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelGenerator(new LabelGenerator());
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setSeriesPaint(0, new Color(10, 80, 150, 128));
    barrenderer.setSeriesPaint(1, new Color(180, 60, 50, 128));
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER);
    barrenderer.setPositiveItemLabelPosition(itemlabelposition);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}
Also used : BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Color(java.awt.Color) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator)

Example 3 with BarRenderer3D

use of org.jfree.chart.renderer.category.BarRenderer3D in project pentaho-platform by pentaho.

the class JFreeChartEngine method createBarLineChart.

private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    String secondValueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    PlotOrientation orientation = chartDefinition.getOrientation();
    // split BarLineChartDefinition in two Definitions
    CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition(chartDefinition.getSession(), chartDefinition.getChartAttributes());
    CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition(chartDefinition.getSession(), chartDefinition.getChartAttributes());
    /*
     * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset =
     * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){}
     */
    // get column and row count of the data set
    int iColumnCount = chartDefinition.getColumnCount();
    int iRowCount = chartDefinition.getRowCount();
    if (iRowCount <= 0) {
        // $NON-NLS-1$
        chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE"));
    }
    // Loop through columns
    for (int r = 0; r < iRowCount; r++) {
        // check if measure should be include in bar or line dataset
        String strMeasureName = (String) chartDefinition.getRowKey(r);
        boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName);
        boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName);
        // getting all values
        for (int c = 0; c < iColumnCount; c++) {
            Comparable compColumnName = chartDefinition.getColumnKey(c);
            Number nValue = chartDefinition.getValue(strMeasureName, compColumnName);
            if (bIsBarColumn) {
                barsDataset.addValue(nValue, strMeasureName, compColumnName);
            }
            if (bIsLineColumn) {
                linesDataset.addValue(nValue, strMeasureName, compColumnName);
            }
        }
    }
    if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) {
        // $NON-NLS-1$
        chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"));
    }
    // Create Axis Objects
    CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis barsAxis = new NumberAxis(valueAxisLabel);
    NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel);
    // set title and font for lines Axis
    linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle());
    linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont());
    if (chartDefinition.getLinesRangeTickFormat() != null) {
        linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat());
    }
    // create renderer
    BarRenderer barRenderer = null;
    LineAndShapeRenderer lineRenderer = null;
    // Determine the type of renderer to use
    if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
        if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
            barRenderer = new StackedBarRenderer3D();
            lineRenderer = new LineRenderer3D();
        } else if (chartDefinition.isStacked()) {
            barRenderer = new StackedBarRenderer();
            lineRenderer = new LineAndShapeRenderer();
        } else {
            barRenderer = new BarRenderer3D();
            lineRenderer = new LineRenderer3D();
        }
    } else {
        barRenderer = new BarRenderer();
        lineRenderer = new LineAndShapeRenderer();
    }
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
        barRenderer.setPositiveItemLabelPosition(position1);
        lineRenderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
        barRenderer.setNegativeItemLabelPosition(position2);
        lineRenderer.setNegativeItemLabelPosition(position2);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
        barRenderer.setPositiveItemLabelPosition(position1);
        lineRenderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
        barRenderer.setNegativeItemLabelPosition(position2);
        lineRenderer.setNegativeItemLabelPosition(position2);
    }
    if (tooltips) {
        barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
        lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }
    if (chartDefinition.getMaxBarWidth() != null) {
        barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
    }
    // setting some line attributes
    lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
    lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible());
    lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());
    /*
     * Create plot and make necessary adjustments for overlaid chart
     */
    // create the plot with bar chart
    CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer);
    // add line renderer
    plot.setRenderer(1, lineRenderer);
    // add lines dataset, renderer and axis to plot
    plot.setDataset(1, linesDataset);
    plot.setRangeAxis(1, linesAxis);
    // map lines to second axis
    plot.mapDatasetToRangeAxis(1, 1);
    // set rendering order
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // set location of second axis
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    // standard settings for plots
    JFreeChartEngine.updatePlot(plot, barsDataset);
    // additional settings for second axis
    ValueAxis secondValueAxis = plot.getRangeAxis(1);
    if (secondValueAxis != null) {
        if (chartDefinition.getLinesRangeTitle() != null) {
            secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle());
        }
        if (chartDefinition.getLinesRangeTitleFont() != null) {
            secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont());
        }
        if (chartDefinition.getLinesRangeTickFont() != null) {
            secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont());
        }
        if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
            secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum());
        }
        if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
            secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum());
        }
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberAxis(org.jfree.chart.axis.NumberAxis) LineRenderer3D(org.jfree.chart.renderer.category.LineRenderer3D) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Example 4 with BarRenderer3D

use of org.jfree.chart.renderer.category.BarRenderer3D 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 5 with BarRenderer3D

use of org.jfree.chart.renderer.category.BarRenderer3D in project sonar-scanner-jenkins by SonarSource.

the class BarChart3D method configureRenderer.

private void configureRenderer(CategoryPlot plot) {
    BarRenderer3D renderer = new BarRenderer3D();
    renderer.setDrawBarOutline(true);
    renderer.setSeriesItemLabelsVisible(0, true);
    renderer.setItemMargin(0);
    plot.setRenderer(renderer);
}
Also used : BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D)

Aggregations

BarRenderer3D (org.jfree.chart.renderer.category.BarRenderer3D)5 JFreeChart (org.jfree.chart.JFreeChart)4 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)4 CategoryPlot (org.jfree.chart.plot.CategoryPlot)4 CategoryAxis (org.jfree.chart.axis.CategoryAxis)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 ValueAxis (org.jfree.chart.axis.ValueAxis)2 StandardCategoryItemLabelGenerator (org.jfree.chart.labels.StandardCategoryItemLabelGenerator)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 PlotOrientation (org.jfree.chart.plot.PlotOrientation)2 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)2 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)2 StackedBarRenderer3D (org.jfree.chart.renderer.category.StackedBarRenderer3D)2 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)2 Color (java.awt.Color)1 GradientPaint (java.awt.GradientPaint)1 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1