Example usage for org.jfree.chart.plot XYPlot setDomainPannable

List of usage examples for org.jfree.chart.plot XYPlot setDomainPannable

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDomainPannable.

Prototype

public void setDomainPannable(boolean pannable) 

Source Link

Document

Sets the flag that enables or disables panning of the plot along the domain axes.

Usage

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value",
            intervalxydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);/*ww  w .  j  a va  2  s. com*/
    xyplot.setDomainAxis(new DateAxis("Date"));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setUseFillPaint(true);
    xyerrorrenderer.setBaseFillPaint(Color.white);
    xyplot.setRenderer(xyerrorrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:DataCharts.LineGraph.java

public static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Customers by Month", "Months", "Customers", dataset);

    String fontName = "SansSerif";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle(" ", new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(false);
    plot.setRangePannable(false);/*from w w  w.java 2s .com*/
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setDrawSeriesLineAsPath(false);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);

    }
    return chart;

}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYShapeRenderer xyshaperenderer = new XYShapeRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(1.0D, 4D, new Color(0, 0, 255));
    lookuppaintscale.add(2D, new Color(100, 100, 255));
    lookuppaintscale.add(3D, new Color(200, 200, 255));
    xyshaperenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyshaperenderer);
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);//from  w  w  w.j  a  v a 2  s .c  o m
    JFreeChart jfreechart = new JFreeChart("XYShapeRendererDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Score");
    numberaxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, numberaxis2);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setMargin(4D, 4D, 40D, 4D);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    jfreechart.addSubtitle(paintscalelegend);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            xydataset, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);//ww  w  .j ava2  s.  c o  m
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setLowerMargin(0.20000000000000001D);
    dateaxis.setUpperMargin(0.20000000000000001D);
    dateaxis.setStandardTickUnits(createStandardDateTickUnits());
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setLowerMargin(0.20000000000000001D);
    numberaxis.setUpperMargin(0.20000000000000001D);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseLinesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1, 5F, new float[] { 10F, 5F }, 0.0F));
    xylineandshaperenderer.setSeriesFillPaint(0, Color.white);
    xylineandshaperenderer.setSeriesFillPaint(1, Color.white);
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xylineandshaperenderer.setDefaultEntityRadius(6);
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(4, 2005)).getFirstMillisecond(),
            600D, 180D, 100D, 3D, createPieChart()));
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(9, 2007)).getFirstMillisecond(),
            1250D, 120D, 100D, 2D, createBarChart()));
    xyplot.setRenderer(xylineandshaperenderer);
    return jfreechart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);//from   w w w  .  ja  v  a  2s  .  c  om
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

/**
 * Creates a chart./*  w w  w  .  ja va2s  . c  o  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setDefaultOutlinePaint(Color.red);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

/**
 * Creates a sample chart./*from w  w  w .j av a  2  s . c  om*/
 *
 * @param dataset  a dataset for the chart.
 *
 * @return A sample chart.
 */
private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setLowerMargin(0.2);
    xAxis.setUpperMargin(0.2);
    xAxis.setStandardTickUnits(createStandardDateTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLowerMargin(0.2);
    yAxis.setUpperMargin(0.2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseLinesVisible(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f,
            new float[] { 10.0f, 5.0f }, 0.0f));
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesFillPaint(1, Color.white);
    renderer.setUseFillPaint(true);

    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100,
            3.0, createPieChart()));
    renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100,
            2.0, createBarChart()));
    plot.setRenderer(renderer);
    return chart;
}

From source file:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a chart.//from   ww w  .  j  av  a  2s  .  co m
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlinePaint(Color.red);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white);

    //register plot as selection change listener
    ext.addSelectionChangeListener(plot);

    return chart;
}

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

/**
 * Creates a chart./*from  w  w w  .  j  a v  a  2  s .  c o m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Stock Prices", "Date", "Price Per Unit", dataset);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setBaseShapesVisible(true);
    r.setBaseShapesFilled(true);
    r.setUseFillPaint(true);
    r.setSeriesFillPaint(0, r.lookupSeriesPaint(0));
    r.setSeriesFillPaint(1, r.lookupSeriesPaint(1));

    //add selection specific rendering
    IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

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

/**
 * Creates a chart.//w w w.java 2s.co m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Stock Prices", "Date", "Price Per Unit", dataset);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setBaseShapesVisible(true);
    r.setBaseShapesFilled(true);
    r.setUseFillPaint(true);
    r.setSeriesFillPaint(0, r.lookupSeriesPaint(0));
    r.setSeriesFillPaint(1, r.lookupSeriesPaint(1));

    r.setDrawOutlines(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}