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:net.sf.dynamicreports.test.jasper.chart.ThermometerChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//  www . j  av a  2 s .  c o m

    JFreeChart chart = getChart("summary.chart1", 0);
    Plot plot = chart.getPlot();
    Assert.assertEquals("renderer", ThermometerPlot.class, plot.getClass());
    ThermometerPlot thermometerPlot = (ThermometerPlot) plot;
    Assert.assertEquals("value", 15, thermometerPlot.getDataset().getValue());
    Assert.assertEquals("data range low", 3d, thermometerPlot.getLowerBound());
    Assert.assertEquals("data range high", 30d, thermometerPlot.getUpperBound());
    Assert.assertEquals("value color", Color.BLUE, thermometerPlot.getValuePaint());
    try {
        Field field = thermometerPlot.getClass().getDeclaredField("valueFormat");
        field.setAccessible(true);
        Assert.assertEquals("value mask", "15.0", ((NumberFormat) field.get(thermometerPlot)).format(15));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
    Assert.assertEquals("value font", new Font("Arial", Font.PLAIN, 10), thermometerPlot.getValueFont());
    Assert.assertEquals("value location", ThermometerPlot.BULB, thermometerPlot.getValueLocation());
    Assert.assertEquals("mercury color", Color.LIGHT_GRAY, thermometerPlot.getMercuryPaint());
    try {
        Field field = thermometerPlot.getClass().getDeclaredField("subrangeInfo");
        field.setAccessible(true);
        double[][] subrangeInfo = (double[][]) field.get(thermometerPlot);
        Assert.assertEquals("low data range low", 8d, subrangeInfo[2][0]);
        Assert.assertEquals("low data range high", 10d, subrangeInfo[2][1]);
        Assert.assertEquals("medium data range low", 18d, subrangeInfo[1][0]);
        Assert.assertEquals("medium data range high", 20d, subrangeInfo[1][1]);
        Assert.assertEquals("high data range low", 28d, subrangeInfo[0][0]);
        Assert.assertEquals("high data range high", 30d, subrangeInfo[0][1]);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

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

public JDBCPieChartDemo(String s) {
    super(s);/*  w w  w.ja  v  a2  s .c  o  m*/
    PieDataset piedataset = readData();
    JFreeChart jfreechart = ChartFactory.createPieChart("JDBC Pie Chart Demo", piedataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.yellow);
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    pieplot.setNoDataMessage("No data available");
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    setContentPane(chartpanel);
}

From source file:net.sf.dynamicreports.test.jasper.chart.SpiderChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from w  w  w .j ava 2  s . c om*/

    JRPrintFrame printFrame = (JRPrintFrame) getElementAt("summary.list1", 0);

    JRPrintImage image = (JRPrintImage) printFrame.getElements().get(0);
    JFreeChart chart = getChart(image);
    SpiderWebPlot plot = (SpiderWebPlot) chart.getPlot();
    Assert.assertEquals("max value", 10d, plot.getMaxValue());
    Assert.assertEquals("rotation", Rotation.ANTICLOCKWISE, plot.getDirection());
    Assert.assertEquals("table order", org.jfree.util.TableOrder.BY_COLUMN, plot.getDataExtractOrder());
    Assert.assertFalse("web filled", plot.isWebFilled());
    Assert.assertEquals("start angle", 20d, plot.getStartAngle());
    Assert.assertEquals("head percent", 30d, plot.getHeadPercent());
    Assert.assertEquals("interior gap", 0.15d, plot.getInteriorGap());
    Assert.assertEquals("axis line color", Color.RED, plot.getAxisLinePaint());
    Assert.assertEquals("interior gap", 2f, ((BasicStroke) plot.getAxisLineStroke()).getLineWidth());
    Assert.assertEquals("label color", Color.BLUE, plot.getLabelPaint());
    Assert.assertEquals("label gap", 2d, plot.getAxisLabelGap());
    Assert.assertTrue("label font", plot.getLabelFont().isBold());

    image = (JRPrintImage) printFrame.getElements().get(1);
    chart = getChart(image);
    plot = (SpiderWebPlot) chart.getPlot();
    Assert.assertEquals("title", "title", chart.getTitle().getText());
    Assert.assertEquals("subtitle", "subtitle", ((TextTitle) chart.getSubtitle(1)).getText());
}

From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java

public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height,
        File fileName, int resolution) throws IOException {
    // Background color
    Paint saved = chart.getBackgroundPaint();
    if (((Color) saved).getAlpha() == 0) {
        chart.setBackgroundPaint(Color.WHITE);
        chart.setBackgroundImageAlpha(255);
        if (chart.getLegend() != null)
            chart.getLegend().setBackgroundPaint(Color.WHITE);
        // legends and stuff
        for (int i = 0; i < chart.getSubtitleCount(); i++)
            if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
                ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

        // apply bg
        chart.getPlot().setBackgroundPaint(Color.WHITE);
    }/*from  ww  w.  jav  a 2s. c  o  m*/
    //
    if (resolution == 72)
        writeChartToJPEG(chart, width, height, fileName);
    else {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
        try {
            BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution,
                    BufferedImage.TYPE_INT_RGB);
            EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
        } finally {
            out.close();
        }
    }
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBoxAndWhiskerChart.java

protected void init() {
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);/*ww  w  . j a va  2 s  . c om*/
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart(getName(), new Font("SansSerif", Font.BOLD, 14), plot, true);

    init(chart.getPlot());
}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setNextCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to next value if not on last already
    for (int i = 0; i < dataSampler.getLastToDisplay().size() - 1; i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            plot.setDomainCrosshairValue(dataset.getXValue(0, i + 1));
            plot.setRangeCrosshairValue(dataset.getYValue(0, i + 1));
            break;
        }//ww  w. ja va2 s .c o m
    }

}

From source file:picocash.components.panel.statistic.AbstractPieStatisticComponent.java

private final void init() {
    this.title = getTitle();
    this.dataset = new DefaultPieDataset();
    this.chartPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));
    final JFreeChart piechart = ChartFactory.createPieChart(title, dataset, true, true, Locale.getDefault());
    ((PiePlot) piechart.getPlot()).setLabelGenerator(null);
    piechart.setBorderVisible(false);//  w  w w. ja v  a 2  s . co m
    piechart.setAntiAlias(true);
    ChartPanel chart = new ChartPanel(piechart, 300, 300, 200, 200, 400, 400, false, false, false, false, false,
            true);
    chart.getChart().getPlot().setBackgroundAlpha(0);
    chart.getChart().getPlot().setOutlineVisible(false);
    this.chartPanel.setOpaque(false);
    this.chartPanel.add(chart, "growx, aligny top");
}

From source file:JFreeChartScriptlet.java

@Override
public void afterReportInit() throws JRScriptletException {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Java", 43.2d);
    dataset.setValue("Visual Basic", 10.0d);
    dataset.setValue("C/C++", 17.5d);
    dataset.setValue("PHP", 32.5d);
    dataset.setValue("Perl", 1.0d);

    JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart 3D Demo 1", dataset, true, true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);/*from   www . j av  a2  s  .  c o m*/
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    /*   */
    this.setVariableValue("Chart", new JCommonDrawableRendererImpl(chart));
}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setPrevCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to previous value if not on first already
    for (int i = 0; i < dataSampler.getLastToDisplay().size(); i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            if (i > 0) {
                plot.setDomainCrosshairValue(dataset.getXValue(0, i - 1));
                plot.setRangeCrosshairValue(dataset.getYValue(0, i - 1));
            }//  w w w  . ja  va  2 s.c  om
            break;
        }
    }

}

From source file:com.polivoto.vistas.acciones.Datos.java

private JFreeChart crearChartPie(PieDataset dataset, String titulo) {
    JFreeChart chart = ChartFactory.createPieChart(titulo, dataset, false, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);/*from w ww  .j a  v  a 2s .co  m*/
    plot.setDirection(Rotation.ANTICLOCKWISE);

    plot.setNoDataMessage("No hay votos");
    try {
        if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getInt("participantes") != 0) {
            int j = 0;
            for (int i = 0; i < ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                    .length(); i++) {
                try {
                    if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                            .getJSONObject(i).getString("reactivo").equals("Anular mi voto")) {
                        plot.setSectionPaint("Nulo", Color.lightGray);
                    } else {
                        plot.setSectionPaint(ac.getConteoOpcionesPregunta().getJSONObject(pox)
                                .getJSONArray("conteo").getJSONObject(i).getString("reactivo"), colores.get(j));
                        j++;
                    }
                } catch (JSONException ex) {
                    ex.printStackTrace();
                }
            }
        }
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    plot.setSimpleLabels(true);
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {2} de votos",
            new DecimalFormat("0"), new DecimalFormat("0.000%"));
    plot.setLabelGenerator(gen);
    if (rotating) {
        final Rotator rotate = new Rotator(plot);
        rotate.start();
    }
    return chart;
}