Search in sources :

Example 96 with CategoryPlot

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

the class MChart method createStackedBarChart.

private JFreeChart createStackedBarChart() {
    JFreeChart chart = ChartFactory.createStackedBarChart(// 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 97 with CategoryPlot

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

use of org.jfree.chart.plot.CategoryPlot in project bamboobsc by billchen198318.

the class CommonBarChartAction method fillChart.

private void fillChart(String title, String categoryLabel, String valueLabel, List<String> names, List<Float> values, List<String> colors, boolean horizontal) throws Exception {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.addValue(values.get(ix), "", names.get(ix));
    }
    this.chart = ChartFactory.createBarChart3D(// title
    title, categoryLabel, valueLabel, data, (horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL), false, false, false);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Font(java.awt.Font)

Example 99 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project opennms by OpenNMS.

the class ChartUtils method addSubLabels.

/**
 * @param barChart TODO
 * @param subLabelClass
 */
private static void addSubLabels(JFreeChart barChart, String subLabelClass) {
    ExtendedCategoryAxis subLabels;
    CategoryPlot plot = barChart.getCategoryPlot();
    try {
        subLabels = (ExtendedCategoryAxis) Class.forName(subLabelClass).newInstance();
        List<?> cats = plot.getCategories();
        for (int i = 0; i < cats.size(); i++) {
            subLabels.addSubLabel((Comparable<?>) cats.get(i), cats.get(i).toString());
        }
        plot.setDomainAxis(subLabels);
    } catch (InstantiationException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (IllegalAccessException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (ClassNotFoundException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    }
}
Also used : ExtendedCategoryAxis(org.jfree.chart.axis.ExtendedCategoryAxis) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint)

Example 100 with CategoryPlot

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

the class MonitoringPage method createProgressChart.

private JFreeChart createProgressChart(Map<String, Integer> chartValues, int aMaxValue, boolean aIsPercentage) {
    // fill dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (aMaxValue > 0) {
        for (String chartValue : chartValues.keySet()) {
            dataset.setValue(chartValues.get(chartValue), "Completion", chartValue);
        }
    }
    // create chart
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(null);
    plot.setNoDataMessage("No data");
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0, 20, 0, 20));
    if (aMaxValue > 0) {
        plot.getRangeAxis().setRange(0.0, aMaxValue);
        ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0"));
        // as 0 0 1 1 1 - NumberTickUnit automatically determines the range
        if (!aIsPercentage && aMaxValue <= 10) {
            TickUnits standardUnits = new TickUnits();
            NumberAxis tick = new NumberAxis();
            tick.setTickUnit(new NumberTickUnit(1));
            standardUnits.add(tick.getTickUnit());
            plot.getRangeAxis().setStandardTickUnits(standardUnits);
        }
    } else {
        plot.getRangeAxis().setVisible(false);
        plot.getDomainAxis().setVisible(false);
    }
    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    // renderer.setGradientPaintTransformer(new
    // StandardGradientPaintTransformer(
    // GradientPaintTransformType.HORIZONTAL));
    renderer.setSeriesPaint(0, Color.BLUE);
    chart.getCategoryPlot().setRenderer(renderer);
    return chart;
}
Also used : TickUnits(org.jfree.chart.axis.TickUnits) NumberAxis(org.jfree.chart.axis.NumberAxis) DecimalFormat(java.text.DecimalFormat) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit)

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