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:BarChartCustomizer.java

public void customize(JFreeChart chart, JRChart jasperChart) {
    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    renderer.setSeriesPaint(0, Color.green);
    renderer.setSeriesPaint(1, Color.orange);
}

From source file:jasperreport.BarChartCustomizer.java

public void customize(JFreeChart chart, JRChart jasperChart) {
    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesPaint(1, Color.orange);
    renderer.setBaseItemLabelsVisible(true);
}

From source file:Visao.Relatorio.Grafico_QuantidadeReclamacoesUF.java

private void grafico(JFreeChart chart) {

    CategoryPlot p = chart.getCategoryPlot();

    p.setRangeGridlinePaint(Color.BLUE);

    ChartPanel panel = new ChartPanel(chart);
    panel.setVisible(true);/*from   www .  java 2  s. co m*/

    panel.setSize(screenSize.width - 10, screenSize.height - 140);
    this.add(panel);
}

From source file:org.bonitasoft.simulation.reporting.jasperreport.BarChartVisibleBarLabel.java

public void customize(JFreeChart chart, JRChart jasperChart) {

    BarRenderer bsr = (BarRenderer) chart.getCategoryPlot().getRenderer();
    bsr.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bsr.setItemLabelsVisible(true);/* w  w  w . j  a v  a2 s . c  o  m*/
    // Set position of Items label : center
    bsr.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    bsr.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    // If there isn't enough space to draw the ItemLabel...
    bsr.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER));
    bsr.setNegativeItemLabelPositionFallback(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER));
}

From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFree3DBarChartGenerator.java

/**
 * Creates cylinder bar chart and creates range axis for it. </p>
 *
 * @param chartDocContext Current chart's document context
 * @param data            Current chart data
 * @return Returns JFreeChart object that is a layered bar chart.
 *///from w  ww. j ava 2  s. c o  m
protected JFreeChart doCreateChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) {
    final JFreeChart chart = createChart(chartDocContext, data, JFreeBarChartTypes.DEFAULT);
    chart.getCategoryPlot().setRenderer(new BarRenderer3D());
    /*
     * Doing all the render stuff and then off to create range axis.
     * NOTE: The chart object will be updated.
     */
    createRangeAxis(chartDocContext, data, chart);
    return chart;
}

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

/**
 * DOC bZhou Comment method "decorate"./*from w  w  w.  j  a v a  2 s.  co  m*/
 * 
 * @param chart
 */
public static void decorate(JFreeChart chart, PlotOrientation orientation) {
    if (chart != null) {
        // TDQ-11522: Set white background on charts in the editors
        chart.setBackgroundPaint(Color.white);
        // TDQ-11522~
        Plot plot = chart.getPlot();
        if (plot instanceof CategoryPlot) {
            decorateCategoryPlot(chart, orientation);

            CategoryDataset dataset = chart.getCategoryPlot().getDataset();
            int rowCount = dataset != null ? dataset.getRowCount() : 20;
            for (int i = 0; i < rowCount; i++) {
                // by zshen bug 14173 add the color in the colorList when chart need more the color than 8.
                if (i >= COLOR_LIST.size()) {
                    COLOR_LIST.add(generateRandomColor(COLOR_LIST));
                }
                // ~14173
                ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i));
            }

        } else if (plot instanceof XYPlot) {
            decorateXYPlot(chart);

            int count = chart.getXYPlot().getDataset().getSeriesCount();
            for (int i = 0; i < count; i++) {
                // by zshen bug 14173 add the color in the colorList when chart need the colors more than 8.
                if (i >= COLOR_LIST.size()) {
                    COLOR_LIST.add(generateRandomColor(COLOR_LIST));
                }
                // ~14173
                ((XYPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i));
            }
        } else if (plot instanceof PiePlot) {
            decoratePiePlot(chart);

            // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart
            PieDataset piedataset = ((PiePlot) plot).getDataset();
            for (int i = 0; i < piedataset.getItemCount(); i++) {
                if (i >= PIE_COLOR_LIST.size()) {
                    PIE_COLOR_LIST.add(generateRandomColor(PIE_COLOR_LIST));
                }
                Comparable<?> key = piedataset.getKey(i);
                ((PiePlot) plot).setSectionPaint(key, PIE_COLOR_LIST.get(i));
            }
            // TDQ-8046~
        }
    }
}

From source file:barChart1.BarChartDemo.java

/**
 * Creates a sample chart./*from   ww  w .  ja v  a 2 s.  co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("Belgium vs Italy vs Ireland ", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(64, 0, 0));

    GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp2);

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

    return chart;

}

From source file:org.neo4j.bench.chart.AbstractJFreeChart.java

protected void rotateCategoryAxis(JFreeChart chart, double piAngle) {
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(piAngle));
}

From source file:ca.sqlpower.wabit.swingui.chart.effect.BarChartAnimatorFactory.java

public ChartAnimator createAnimator(JFreeChart chart) throws CantAnimateException {
    DefaultCategoryDataset dataset;//www.j a  v  a  2 s  .com
    if (chart.getCategoryPlot().getDataset() instanceof DefaultCategoryDataset) {
        dataset = (DefaultCategoryDataset) chart.getCategoryPlot().getDataset();
    } else {
        throw new CantAnimateException("Unsupported dataset type " + chart.getCategoryPlot().getDataset());
    }

    chart.getCategoryPlot().getRangeAxis().setAutoRange(false);

    return new BarChartAnimator(getFrameCount(), getFrameDelay(), dataset, interpolator);
}

From source file:app.Histogram.java

public void histogramDesign(JFreeChart chart) {
    final CategoryPlot plot = chart.getCategoryPlot();
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();

    renderer.setDrawBarOutline(false);/*from w ww .  j a v a  2s. com*/
    renderer.setItemMargin(0.10);
    renderer.setShadowVisible(false);

    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.black, 0.0f, 0.0f, Color.black);

    final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1));

    renderer.setSeriesPaint(0, gp0);
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 500));

    JPanel panelJPanel = new JPanel();
    panelJPanel.removeAll();
    //panelJComboBox.removeAll();
    PlotWindow hist = new PlotWindow();
    hist.setVisible(true);
    // HistogtamWindow f = new HistogtamWindow();
    // HistogtamWindow f2 = f.getInstance();
    // f2.setVisible(true);
    // f2.getHistogramPanel().add(chartPanel);
    panelJPanel.add(chartPanel);
    hist.setContentPane(panelJPanel);
}