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

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

Introduction

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

Prototype

public void setDomainCrosshairVisible(boolean flag) 

Source Link

Document

Sets the flag indicating whether or not the domain crosshair is visible and, if the flag changes, sends a PlotChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/* www  . j  a v a2  s .  c om*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    return jfreechart;
}

From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java

public static JPanel createXYScatterPlotChart(XYDataset data, String x, String y, int w, int h) {
    //XYDataset data = new SampleXYDataset2();
    JFreeChart chart = ChartFactory.createScatterPlot(null, // the title of the chart
            x, // the label for the X axis
            y, // the label for the Y axis
            data, // the dataset for the chart
            PlotOrientation.VERTICAL, // the orientation of the chart
            true, // a flag specifying whether or not a legend is required
            true, // a flag specifying whether or not tooltips should be generated
            false); // a flag specifying whether or not the chart should generate URLs

    XYPlot plot = (XYPlot) chart.getXYPlot();

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    /*//from w w w.java  2 s .c  o m
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
             
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setFixedDimension(50);
            
    ValueAxis yAxis = plot.getRangeAxis();
    */
    //StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    //renderer.setSeriesPaint(0, java.awt.Color.red);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(w, h));

    return chartPanel;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYLineChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w  w  w  . j  a va  2s.  c  om*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYAreaChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYAreaChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );//w  w  w  .j  av  a2 s  .  c  om

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYStepChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYStepChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*  w  w  w  .ja  va2 s.co m*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createXYStepAreaChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYStepAreaChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );//w  w  w. j  av  a 2  s. c om

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createScatterChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createScatterPlot("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from www .j av a  2 s  .  c om*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;

}

From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java

/**
 * Creates a chart./*from www  .  ja  v  a 2s .c  om*/
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", // title
            null, // x-axis label
            "US cents/lb", // y-axis label
            dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf",
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    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);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );//  w w  w .j a v  a  2s . co  m

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

private static JFreeChart createCustomXYStepChart(TimePeriodValuesCollection prices) {
    DateAxis xAxis = new DateAxis(null);
    NumberAxis yAxis = new NumberAxis("price");
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    XYPlot plot = new XYPlot(prices, xAxis, yAxis, null);
    plot.setRenderer(new XYStepRenderer(null, null));
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}