Search in sources :

Example 1 with StandardBarPainter

use of org.jfree.chart.renderer.category.StandardBarPainter in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatStripsLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int total = dataSets.size();
    int v = total / -2;
    for (int i = 0; i < total; i++) {
        // Just to make sure there is always a bar for each data set name
        if (v == 0.0)
            v = 1;
        dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
    }
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // 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, 0.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.setLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setMaximumCategoryLabelLines(1);
    domainAxis.setCategoryMargin(0.0);
    if (total > 4) {
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
    } else {
        domainAxis.setMaximumCategoryLabelLines(2);
    }
    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<>();
    for (int i = 0; i < total; i++) {
        Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
        itemColors.add(ColorUtil.getColor(n.doubleValue(), -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) Paint(java.awt.Paint) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 2 with StandardBarPainter

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

the class MChart method createBarChart.

private JFreeChart createBarChart() {
    JFreeChart chart = ChartFactory.createBarChart(// chart title
    getName(), // domain axis label
    getDomainLabel(), // range axis label
    getRangeLabel(), // data
    getCategoryDataset(), X_AD_Chart.CHARTORIENTATION_Horizontal.equals(getChartOrientation()) ? PlotOrientation.HORIZONTAL : // orientation
    PlotOrientation.VERTICAL, // include legend
    isDisplayLegend(), // tooltips?
    true, // URLs?
    true);
    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);
    setupCategoryChart(chart);
    return chart;
}
Also used : StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 3 with StandardBarPainter

use of org.jfree.chart.renderer.category.StandardBarPainter in project jgnash by ccavanaugh.

the class BudgetSparkline method getSparklineImage.

public static Icon getSparklineImage(final List<BigDecimal> amounts) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final boolean[] negate = new boolean[amounts.size()];
    for (int i = 0; i < amounts.size(); i++) {
        dataset.addValue(amounts.get(i), CATEGORY, i);
        negate[i] = amounts.get(i).signum() == -1;
    }
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setAxisLineVisible(false);
    xAxis.setVisible(false);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setAutoRange(true);
    yAxis.setVisible(false);
    BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(final int row, final int column) {
            return negate[column] ? Color.RED : Color.BLACK;
        }
    };
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setInsets(INSETS);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(CLEAR);
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(CLEAR);
    Icon icon = EMPTY_ICON;
    try {
        byte[] image = ENCODER.encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
        icon = new ImageIcon(image);
    } catch (IOException ex) {
        Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
    }
    return icon;
}
Also used : ImageIcon(javax.swing.ImageIcon) NumberAxis(org.jfree.chart.axis.NumberAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) IOException(java.io.IOException) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 4 with StandardBarPainter

use of org.jfree.chart.renderer.category.StandardBarPainter in project neo4j by neo4j.

the class CoverageChartWriter method createBarChart.

private JFreeChart createBarChart(Map<String, Integer> data) {
    if (cached != null) {
        return cached;
    }
    JFreeChart chart = ChartFactory.createBarChart("Spec suite tag distribution", "Tags", "Occurrences in queries", createCategoryDataset(data));
    // styling
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.addRangeMarker(new ValueMarker(HORIZONTAL_LINE_VALUE, Color.BLACK, new BasicStroke(2)));
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, ChartColor.DARK_RED);
    renderer.setBarPainter(new StandardBarPainter());
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    cached = chart;
    return chart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ValueMarker(org.jfree.chart.plot.ValueMarker) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 5 with StandardBarPainter

use of org.jfree.chart.renderer.category.StandardBarPainter in project cubrid-manager by CUBRID.

the class CombinedBarTimeSeriesChart method createBarChart.

/**
	 * Create a bar chart instance.
	 * 
	 * @return a bar chart instance
	 */
private JFreeChart createBarChart() {
    bardataset = new DefaultCategoryDataset();
    if (valueMap != null) {
        for (String key : valueMap.keySet()) {
            bardataset.addValue(0D, key, "");
        }
    }
    bardataset.addValue(barMax, "100", "");
    JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", bardataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setBorderStroke(new BasicStroke(0.0f));
    chart.setBackgroundPaint(Color.BLACK);
    //plot
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setOutlineVisible(false);
    RectangleInsets rectangleInsets = new RectangleInsets();
    categoryplot.setAxisOffset(rectangleInsets);
    categoryplot.setBackgroundPaint(Color.BLACK);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(false);
    //renderer
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(0);
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setMaximumBarWidth(0.6);
    stackedbarrenderer.setItemMargin(0);
    //painter
    StandardBarPainter painter = new StandardBarPainter() {

        private static final long serialVersionUID = -3124115075260902181L;

        public void paintBar(Graphics2D g2, BarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
            Paint itemPaint = renderer.getItemPaint(row, column);
            GradientPaintTransformer t = renderer.getGradientPaintTransformer();
            if (t != null && itemPaint instanceof GradientPaint) {
                itemPaint = t.transform((GradientPaint) itemPaint, bar);
            }
            g2.setPaint(itemPaint);
            double height = bar.getHeight();
            double width = bar.getWidth();
            double x = bar.getBounds2D().getX();
            double y = bar.getBounds2D().getY();
            int barNumber = (int) (height / 2 + 0.5);
            if (height < 1 && height > 0.5) {
                barNumber = 1;
            }
            for (int i = 0; i < barNumber; i++) {
                RectangularShape subBarLeft = new Rectangle2D.Double(x, y, width / 2, 0.8);
                g2.fill(subBarLeft);
                RectangularShape subBarRight = new Rectangle2D.Double(x + width / 2 + 1, y, width / 2, 0.8);
                g2.fill(subBarRight);
                y += 2;
            }
            if (renderer.isDrawBarOutline()) {
                Stroke stroke = renderer.getItemOutlineStroke(row, column);
                Paint paint = renderer.getItemOutlinePaint(row, column);
                if (stroke != null && paint != null) {
                    g2.setStroke(stroke);
                    g2.setPaint(paint);
                    g2.draw(bar);
                }
            }
        }
    };
    stackedbarrenderer.setBarPainter(painter);
    stackedbarrenderer.setSeriesPaint(0, Color.GREEN);
    stackedbarrenderer.setSeriesPaint(1, Color.RED);
    int backPaintOrder = 1;
    if (valueMap != null) {
        backPaintOrder = valueMap.size();
    }
    stackedbarrenderer.setSeriesPaint(backPaintOrder, new Color(136, 200, 135));
    stackedbarrenderer.setShadowVisible(false);
    stackedbarrenderer.setDrawBarOutline(false);
    //categoryAxis
    categoryAxis = categoryplot.getDomainAxis();
    categoryAxis.setAxisLineVisible(false);
    //	categoryAxis.setCategoryMargin(0);
    categoryAxis.setMinorTickMarksVisible(false);
    categoryAxis.setTickLabelsVisible(false);
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setLabelPaint(Color.GREEN);
    categoryAxis.setLabelFont(new Font("", 0, 10));
    //valueAxis
    ValueAxis valueAxis = categoryplot.getRangeAxis();
    valueAxis.setVisible(false);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) GradientPaintTransformer(org.jfree.ui.GradientPaintTransformer) Color(java.awt.Color) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangularShape(java.awt.geom.RectangularShape) RectangleInsets(org.jfree.ui.RectangleInsets) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)10 CategoryPlot (org.jfree.chart.plot.CategoryPlot)10 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)10 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)10 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)6 Paint (java.awt.Paint)5 CategoryAxis (org.jfree.chart.axis.CategoryAxis)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 RectangleInsets (org.jfree.ui.RectangleInsets)5 Color (java.awt.Color)4 BasicStroke (java.awt.BasicStroke)2 ArrayList (java.util.ArrayList)2 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 Font (java.awt.Font)1 GradientPaint (java.awt.GradientPaint)1 Graphics2D (java.awt.Graphics2D)1 Stroke (java.awt.Stroke)1 RectangularShape (java.awt.geom.RectangularShape)1