Example usage for org.jfree.chart JFreeChart getCategoryPlot

List of usage examples for org.jfree.chart JFreeChart getCategoryPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getCategoryPlot.

Prototype

public CategoryPlot getCategoryPlot() 

Source Link

Document

Returns the plot cast as a CategoryPlot .

Usage

From source file:fr.paris.lutece.plugins.form.business.GraphTypeBarChart.java

/**
* return the JFreeChart BarChart graph//w  w w  .  j av a2 s  .  c o  m
* @param listStatistic listStatistic
* @param strGraphTitle graph title
* @param nGraphThreeDimension true if the graph must be in three dimension
* @param nGraphLabelValue true if the labels must appear in the graph
* @return the JFreeChart graph associate to the graph type
*/

//Cration de l'histogramme
public static JFreeChart createBarChart(List<StatisticEntrySubmit> listStatistic, String strGraphTitle,
        boolean nGraphThreeDimension, boolean nGraphLabelValue) {
    JFreeChart chart;
    CategoryDataset dataset = createBarChartDataset(listStatistic);

    if (nGraphThreeDimension) {
        chart = ChartFactory.createBarChart3D(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL,
                true, false, false);
    } else {
        chart = ChartFactory.createBarChart(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL, true,
                false, false);
    }

    CategoryPlot categoryPlot = chart.getCategoryPlot();
    CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    CategoryLabelPositions labelPositions = CategoryLabelPositions.UP_45;
    categoryAxis.setCategoryLabelPositions(labelPositions);

    BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

    if (nGraphLabelValue) {
        renderer.setItemLabelsVisible(true);

        DecimalFormat decimalformat1 = new DecimalFormat("#.#");
        renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));

        if (nGraphThreeDimension) {
            renderer.setPositiveItemLabelPositionFallback(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
            categoryPlot.setRenderer(renderer);
        }
    }

    return chart;
}

From source file:grafici.StatisticheBarChart3D.java

/**
 * Creates a sample chart./*w w  w  .  j av  a2 s  .c  o m*/
 * 
 * @param dataset
 *            the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset, Table results, int variabile1, int variabile2,
        int valore) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart3D(titolo, // chart
            // title
            results.getColumn(variabile2).getText().toUpperCase(), // domain axis label
            results.getColumn(valore).getText().toUpperCase(), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    final BarRenderer r = (BarRenderer) renderer;

    return chart;

}

From source file:com.sun.japex.ChartGenerator.java

static private void configureLineChart(JFreeChart chart) {
    CategoryPlot plot = chart.getCategoryPlot();

    final DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            // Draw a small diamond 
            new Shape[] { new Polygon(new int[] { 3, 0, -3, 0 }, new int[] { 0, 3, 0, -3 }, 4) });
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDrawingSupplier(supplier);//w w w . j  a v a2s . c  om

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setStroke(new BasicStroke(2.0f));
}

From source file:weka.core.ChartUtils.java

/**
 * Render a histogram chart from summary data (i.e. a list of bin labels and
 * corresponding frequencies) to a buffered image
 * //w ww  . j  a va  2 s.c o m
 * @param width the width of the resulting image
 * @param height the height of the resulting image
 * @param bins the list of bin labels
 * @param freqs the corresponding bin frequencies
 * @param additionalArgs optional arguments to the renderer (may be null)
 * @return a histogram as a buffered image
 * @throws Exception if a problem occurs
 */
public static BufferedImage renderHistogramFromSummaryData(int width, int height, List<String> bins,
        List<Double> freqs, List<String> additionalArgs) throws Exception {

    JFreeChart chart = getHistogramFromSummaryDataChart(bins, freqs, additionalArgs);
    CategoryAxis axis = chart.getCategoryPlot().getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    Font newFont = new Font("SansSerif", Font.PLAIN, 11);
    axis.setTickLabelFont(newFont);
    BufferedImage image = chart.createBufferedImage(width, height);
    return image;
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * Added TDQ-8673: set the display decimal format as: x.xx
 * //from w  ww.j a  v a2 s  .  co  m
 * @param chart
 */
public static void setDisplayDecimalFormat(JFreeChart chart) {
    CategoryPlot plot = chart.getCategoryPlot();

    plot.getRenderer().setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat(DOUBLE_FORMAT))); //$NON-NLS-1$

}

From source file:spec.reporter.Utils.java

public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) {

    // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score
    Color[] colors = new Color[scores.size() + 8];

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int count = 0;

    Iterator<String> iteratorBenchmarks = scores.keySet().iterator();
    while (iteratorBenchmarks.hasNext()) {
        String key = iteratorBenchmarks.next();
        Double score = scores.get(key);
        if (Utils.isValidScore(score)) {
            dataset.addValue(score, key, key);
            colors[count++] = (Color) colorMap.get(key);
        }//  www  .j a v a 2  s  .  c  o  m
    }

    if (Utils.isValidScore(compositeScore)) {
        dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME);
        colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME);
    }

    JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title
            "", // domain axis label
            "", dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );

    CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset);
    for (int i = 0; i < count; i++) {
        Color paint = (Color) colors[i];
        if (paint != null) {
            renderer.setSeriesPaint(i, paint);
        }
    }

    try {
        ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600,
                50 + (dataset.getRowCount()) * 20);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.fhaes.fhrecorder.util.ColorBar.java

/**
 * Creates a chart when given a data set.
 * /*w  ww.j  av a 2  s . c  o m*/
 * @param dataset to be plotted.
 * @return the created chart.
 */
private static JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL,
            false, true, false);

    chart.setPadding(RectangleInsets.ZERO_INSETS);
    chart.setBorderVisible(false);

    StackedBarRenderer renderer = new StackedBarRenderer();
    renderer.setBarPainter(new StandardBarPainter()); // Remove shine
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setShadowVisible(false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);
    // plot.setBackgroundAlpha(0.0f);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLowerMargin(0);
    plot.getRangeAxis().setUpperMargin(0);

    plot.getDomainAxis().setVisible(false);
    plot.getDomainAxis().setLowerMargin(0);
    plot.getDomainAxis().setUpperMargin(0);

    return chart;
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * Returns true if this string contains the chinese char values. DOC yyi Comment method
 * "isContainsChinese".2010-09-26:14692.
 * //from   w  ww. j ava2s  . c o m
 * @param str
 * @return
 * @deprecated replace it with isContainCJKCharacter(String str)
 */
@Deprecated
private static boolean isContainsChineseColumn(JFreeChart chart) {
    Object[] columnNames = chart.getCategoryPlot().getDataset().getColumnKeys().toArray();
    String regEx = "[\u4e00-\u9fa5]";//$NON-NLS-1$
    Pattern pat = Pattern.compile(regEx);
    boolean flg = false;
    for (Object str : columnNames) {
        Matcher matcher = pat.matcher(str.toString());
        if (matcher.find()) {
            flg = true;
            break;
        }
    }
    return flg;
}

From source file:common.utility.ChartHelper.java

public static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart3D("Quantity Of Citizens Of Each Area", // chart title
            "(Include unactived people)", // domain axis label
            "Quantity", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );// w w  w  . j av a2 s.  c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.yellow); // Set the background colour of the chart
    chart.getTitle().setPaint(Color.blue); // Adjust the colour of the title
    CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph
    p.setBackgroundPaint(Color.black); // Modify the plot background 
    p.setRangeGridlinePaint(Color.red);

    return chart;

}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * create bar chart with customized bar render class which can be adapted in JFreeChart class.
 * /*  w w w . ja  va  2  s.c  o  m*/
 * @param chart
 * @param barRenderer
 */
public static void decorateBarChart(JFreeChart chart, BarRenderer barRenderer) {
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getRangeAxis().setUpperMargin(0.08);
    plot.setRangeGridlinesVisible(true);

    barRenderer.setBaseItemLabelsVisible(true);
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    barRenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    barRenderer.setBaseNegativeItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    // MOD klliu 2010-09-25 bug15514: The chart of summary statistic indicators not beautiful
    barRenderer.setMaximumBarWidth(0.1);
    // renderer.setItemMargin(0.000000005);
    // renderer.setBase(0.04);
    // ADD yyi 2009-09-24 9243
    barRenderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator(NEW_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance()));

    // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow
    barRenderer.setShadowVisible(false);
    // TDQ-5251~

    // CategoryAxis domainAxis = plot.getDomainAxis();
    // domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    plot.setRenderer(barRenderer);
}