Search in sources :

Example 1 with CategoryPlot

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

use of org.jfree.chart.plot.CategoryPlot in project libresonic by Libresonic.

the class UserChartController method createChart.

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);
    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);
    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);
    chart.setBackgroundPaint(bgColor);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);
    return chart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Example 3 with CategoryPlot

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

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

the class GraphBuilder method setupCategoryChart.

private void setupCategoryChart(JFreeChart chart) {
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(92 / 255f, 178 / 255f, 232 / 255f));
    renderer.setSeriesPaint(1, new Color(56 / 255f, 97 / 255f, 119 / 255f));
    renderer.setSeriesPaint(2, new Color(242 / 255f, 70 / 255f, 78 / 255f));
    renderer.setSeriesPaint(3, Color.orange);
    renderer.setSeriesPaint(4, new Color(147 / 255f, 196 / 255f, 51 / 255f));
    renderer.setSeriesPaint(5, new Color(210 / 255f, 247 / 255f, 91 / 255f));
    renderer.setSeriesPaint(6, new Color(129 / 255f, 235 / 255f, 249 / 255f));
    renderer.setSeriesPaint(7, new Color(60 / 255f, 84 / 255f, 8 / 255f));
    renderer.setSeriesPaint(8, new Color(0.8f, 0.8f, 0.8f));
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Color(java.awt.Color) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 5 with CategoryPlot

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

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)189 JFreeChart (org.jfree.chart.JFreeChart)94 CategoryAxis (org.jfree.chart.axis.CategoryAxis)88 NumberAxis (org.jfree.chart.axis.NumberAxis)80 Test (org.junit.Test)72 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)36 ValueAxis (org.jfree.chart.axis.ValueAxis)35 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)32 CategoryDataset (org.jfree.data.category.CategoryDataset)29 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)27 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)24 Paint (java.awt.Paint)23 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)16 LegendItem (org.jfree.chart.LegendItem)15 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)13 RectangleInsets (org.jfree.ui.RectangleInsets)13 ArrayList (java.util.ArrayList)11 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)11 XYPlot (org.jfree.chart.plot.XYPlot)11