Example usage for org.jfree.chart JFreeChart getPlot

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

Introduction

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

Prototype

public Plot getPlot() 

Source Link

Document

Returns the plot for the chart.

Usage

From source file:gui.Histograma.java

private static JFreeChart gerarGrafico(IntervalXYDataset dados) {
    JFreeChart chart = ChartFactory.createHistogram("Histograma", null, null, dados, PlotOrientation.VERTICAL,
            true, true, false);//from   www . ja  v  a 2  s. c  om
    XYPlot plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    return chart;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset,
        DatasetSelectionExtension<PieCursor<String>> ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset);

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("One", new Color(160, 160, 255));
    plot.setSectionPaint("Two", new Color(128, 128, 255 - 32));
    plot.setSectionPaint("Three", new Color(96, 96, 255 - 64));
    plot.setSectionPaint("Four", new Color(64, 64, 255 - 96));
    plot.setSectionPaint("Five", new Color(32, 32, 255 - 128));
    plot.setSectionPaint("Six", new Color(0, 0, 255 - 144));

    plot.setNoDataMessage("No data available");

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)"));
    plot.setLabelBackgroundPaint(new Color(220, 220, 220));

    plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    plot.setSimpleLabels(true);// ww  w  .  j av  a 2  s.c  om
    plot.setInteriorGap(0.1);

    //pie plots done use abstract renderers need to react to selection on our own
    final PieCursor<String> cursor = new PieCursor<String>();

    ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() {
        public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) {
            for (int i = 0; i < dataset.getItemCount(); i++) {
                cursor.setPosition((String) dataset.getKey(i));
                if (event.getSelectionExtension().isSelected(cursor)) {
                    plot.setExplodePercent(cursor.key, 0.15);
                } else {
                    plot.setExplodePercent(cursor.key, 0.0);
                }
            }
        }
    });

    return chart;
}

From source file:org.jfree.chart.demo.YIntervalChartDemo1.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Y Interval Chart Demo", "X", "Y", intervalxydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    xyplot.setRenderer(new YIntervalRenderer());
    return jfreechart;
}

From source file:org.jfree.chart.demo.AxisOffsetsDemo1.java

private static JFreeChart createChart(String s, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(s, "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    return jfreechart;
}

From source file:org.jfree.chart.demo.XYBarChartDemo6.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("XYBarChartDemo6", "X", false, "Y", intervalxydataset,
            PlotOrientation.HORIZONTAL, false, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setUseYInterval(true);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    return jfreechart;
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

/**
 * Enable shadow of renderer? JFreeChart 1.0.11 changed the <b>default</b>
 * look by painting shadows for bars. To revert back to the old look, you
 * can disable the shadows with this method.
 *
 * @param chart JFreeChart./*from   w w w . ja v a  2  s  .  c  o  m*/
 * @param state False, to disable shadow-
 * @since 4.1.0
 */
private static void setShadowVisible(final JFreeChart chart, final boolean state) {
    if (chart != null) {
        final Plot p = chart.getPlot();
        if (p instanceof XYPlot) {
            final XYPlot xyplot = (XYPlot) p;
            final XYItemRenderer xyItemRenderer = xyplot.getRenderer();
            if (xyItemRenderer instanceof XYBarRenderer) {
                final XYBarRenderer br = (XYBarRenderer) xyItemRenderer;
                br.setBarPainter(new StandardXYBarPainter());
                br.setShadowVisible(state);
            }
        } else if (p instanceof CategoryPlot) {
            final CategoryPlot categoryPlot = (CategoryPlot) p;
            final CategoryItemRenderer categoryItemRenderer = categoryPlot.getRenderer();
            if (categoryItemRenderer instanceof BarRenderer) {
                final BarRenderer br = (BarRenderer) categoryItemRenderer;
                br.setBarPainter(new StandardBarPainter());
                br.setShadowVisible(state);
            }
        }
    }
}

From source file:org.jfree.chart.demo.StackedAreaChartDemo1.java

public static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedAreaChart("Stacked Area Chart", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.85F);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setLowerMargin(0.0D);/*from w w w.  j av a  2s  .  c o  m*/
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.setCategoryMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

From source file:org.jfree.chart.demo.XYPolygonAnnotationDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("XYPolygonAnnotationDemo1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYPolygonAnnotation xypolygonannotation = new XYPolygonAnnotation(
            new double[] { 2D, 5D, 2.5D, 8D, 3D, 5D, 2.5D, 2D }, null, null, new Color(200, 200, 255, 100));
    xypolygonannotation.setToolTipText("Target Zone");
    xylineandshaperenderer.addAnnotation(xypolygonannotation, Layer.BACKGROUND);
    return jfreechart;
}

From source file:org.jfree.chart.demo.CylinderChartDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart3D("Cylinder Chart Demo 1", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    Paint apaint[] = createPaint();
    CustomCylinderRenderer customcylinderrenderer = new CustomCylinderRenderer(apaint);
    customcylinderrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    customcylinderrenderer.setBaseOutlinePaint(Color.gray);
    customcylinderrenderer.setBaseOutlineStroke(new BasicStroke(0.3F));
    customcylinderrenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    categoryplot.setRenderer(customcylinderrenderer);
    return jfreechart;
}

From source file:cv.mikusher.freechart.BubbleChart.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("AGE vs WEIGHT vs WORK", "Weight", "AGE", xyzdataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);/*from w  ww  .jav  a  2s  .com*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.2);
    numberaxis.setUpperMargin(0.5);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.8);
    numberaxis1.setUpperMargin(0.9);

    return jfreechart;
}