Search in sources :

Example 6 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 7 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 8 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)

Example 9 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project processdash by dtuma.

the class CGIChartBase method setupCategoryChart.

protected void setupCategoryChart(JFreeChart chart) {
    if (!(chart.getPlot() instanceof CategoryPlot))
        return;
    CategoryPlot cp = chart.getCategoryPlot();
    CategoryAxis catAxis = cp.getDomainAxis();
    ValueAxis otherAxis = cp.getRangeAxis();
    if (!chromeless) {
        String catAxisLabel = data.getColName(0);
        if (catAxisLabel == null)
            catAxisLabel = Translator.translate("Project/Task");
        String otherAxisLabel = Translator.translate(getSetting("units"));
        if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1)
            otherAxisLabel = data.getColName(1);
        if (otherAxisLabel == null)
            otherAxisLabel = Translator.translate("Value");
        String catLabels = getParameter("categoryLabels");
        catAxis.setLabel(catAxisLabel);
        otherAxis.setLabel(otherAxisLabel);
        if ("vertical".equalsIgnoreCase(catLabels))
            catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        else if ("none".equalsIgnoreCase(catLabels))
            catAxis.setTickLabelsVisible(false);
    }
    if (data.numCols() == 1 && getParameter("noSkipLegend") == null) {
        chart.removeLegend();
        chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5));
    }
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.ui.RectangleInsets) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 10 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)

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