Example usage for org.jfree.chart JFreeChart getXYPlot

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

Introduction

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

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:org.apache.qpid.disttest.charting.chartbuilder.BaseChartBuilder.java

private void configureYAxisBounds(final ChartingDefinition chartingDefinition, final JFreeChart chart) {
    if (chart.getPlot() != null && chart.getPlot() instanceof XYPlot) {
        ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
        if (chartingDefinition.getYAxisLowerBound() != null) {
            rangeAxis.setLowerBound(chartingDefinition.getYAxisLowerBound());
        }//  w w w  .  j  av a 2s .  c om
        if (chartingDefinition.getYAxisUpperBound() != null) {
            rangeAxis.setUpperBound(chartingDefinition.getYAxisUpperBound());
        }
    }
}

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

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

    numberOfPagesTest(1);// w w w  .  j a v  a  2  s  .  c  o m

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", CandlestickRenderer.class, renderer.getClass());
    Assert.assertEquals("show volume", false, ((CandlestickRenderer) renderer).getDrawVolume());
    highLowChartDataTest(chart, 0, new Object[][] { { "serie", date1, 50d, 35d, 40d, 47d, 70d },
            { "serie", date2, 55d, 40d, 50d, 45d, 120d }, { "serie", date3, 48d, 41d, 42d, 47d, 90d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}

From source file:FreeMemoryViewer.java

private JFreeChart createChart(XYDataset dataset, String title) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            true, false);/*w  w  w.  j a  v a 2 s .  com*/
    XYPlot plot = chart.getXYPlot();
    XYSplineRenderer renderer = new XYSplineRenderer(); // Curve
    plot.setRenderer(renderer);
    return chart;
}

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

/**
 * Creates a new demo instance./*from  w  w w  . jav a 2  s .  c  o  m*/
 *
 * @param title  the frame title.
 */
public SmallNumberDemo(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Small Numbers");
    series.add(1.0E-5, 1.0E-16);
    series.add(5.0E-5, 2.0E-12);
    series.add(17.3E-5, 5.0E-7);
    series.add(21.2E-5, 9.0E-6);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("Small Number Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setStandardTickUnits(new StandardTickUnitSource());
    plot.getRangeAxis().setStandardTickUnits(new StandardTickUnitSource());

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

}

From source file:net.sf.dynamicreports.test.jasper.AbstractJasperChartTest.java

protected void xyzChartDataTest(JFreeChart chart, int series, String seriesName, Number[][] values) {
    XYZDataset dataset = (XYZDataset) chart.getXYPlot().getDataset();
    int index = 0;
    for (Number[] numbers : values) {
        Assert.assertEquals("chart data series name", seriesName, dataset.getSeriesKey(series));
        Assert.assertEquals("chart data x", numbers[0], dataset.getXValue(series, index));
        Assert.assertEquals("chart data y", numbers[1], dataset.getYValue(series, index));
        Assert.assertEquals("chart data z", numbers[2], dataset.getZValue(series, index));
        index++;/*from  w  w w.  j av a 2  s  . com*/
    }
}

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

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

    numberOfPagesTest(1);//from w ww. j  a va2 s .c  om

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", HighLowRenderer.class, renderer.getClass());
    Assert.assertEquals("show open ticks", true, ((HighLowRenderer) renderer).getDrawOpenTicks());
    Assert.assertEquals("show close ticks", true, ((HighLowRenderer) renderer).getDrawCloseTicks());
    highLowChartDataTest(chart, 0, new Object[][] { { "serie", date1, 50d, 35d, 40d, 47d, 70d },
            { "serie", date2, 55d, 40d, 50d, 45d, 120d }, { "serie", date3, 48d, 41d, 42d, 47d, 90d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}

From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java

@Override
public JFreeChart createChart() {
    JFreeChart chart = super.createChart();

    // set minimum/maximum bounds on the two axes
    XYPlot xyPlot = chart.getXYPlot();
    double cutoff = getPercentParam("cut", 100, 200, 5000);
    xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff));
    xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff));
    xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer()));

    // add a box illustrating the target range
    if (data.numRows() > 0) {
        double box = getPercentParam("pct", 0, 50, 100);
        xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box));
        xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0));
        xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box));
    }//from w  ww .ja v  a 2 s  . c  o m

    return chart;
}

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

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

    numberOfPagesTest(1);//w  w w  .  j  a  v a  2  s .  c  o  m

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", XYDifferenceRenderer.class, renderer.getClass());
    Assert.assertFalse("show shapes", ((XYDifferenceRenderer) renderer).getShapesVisible());
    Assert.assertEquals("positive paint", Color.BLUE, ((XYDifferenceRenderer) renderer).getPositivePaint());
    Assert.assertEquals("negative paint", Color.MAGENTA, ((XYDifferenceRenderer) renderer).getNegativePaint());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}

From source file:slash.navigation.converter.gui.profileview.ProfileView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setForegroundAlpha(0.65F);//from  w  ww .  j av a2  s .co  m
    plot.setDomainGridlinesVisible(preferences.getBoolean(X_GRID_PREFERENCE, true));
    plot.setRangeGridlinesVisible(preferences.getBoolean(Y_GRID_PREFERENCE, true));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(createIntegerTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(createIntegerTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    plot.getRenderer().setBaseToolTipGenerator(null);
    return plot;
}

From source file:net.sf.dynamicreports.test.jasper.AbstractJasperChartTest.java

protected void highLowChartDataTest(JFreeChart chart, int series, Object[][] values) {
    DefaultHighLowDataset dataset = (DefaultHighLowDataset) chart.getXYPlot().getDataset();
    int index = 0;
    for (Object[] value : values) {
        Assert.assertEquals("chart data series", value[0], dataset.getSeriesKey(series));
        Assert.assertEquals("chart data date", value[1], dataset.getXDate(series, index));
        Assert.assertEquals("chart data high value", value[2], dataset.getHigh(series, index));
        Assert.assertEquals("chart data low value", value[3], dataset.getLow(series, index));
        Assert.assertEquals("chart data open value", value[4], dataset.getOpenValue(series, index));
        Assert.assertEquals("chart data close value", value[5], dataset.getClose(series, index));
        Assert.assertEquals("chart data volume value", value[6], dataset.getVolume(series, index));
        index++;// w  ww. j  ava  2  s .  com
    }
}