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.hxzon.demo.jfreechart.XYDatasetDemo2.java

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {

    DateAxis timeAxis = new DateAxis(xAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);/* w ww. j a  v a  2  s.c  om*/
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    //        renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);

    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

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

private static JFreeChart createTimeSeriesChart2(XYDataset dataset) {

    DateAxis timeAxis = new DateAxis(xAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);//w  w w  .j a  va 2 s. c  o m
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);

    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

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

private static JFreeChart createScatterChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }/*from ww  w.j a  v  a  2s .co  m*/

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart("Scatter Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;

}

From source file:org.tolven.graph.GraphMenuEventHandler.java

/**
 * Creates a chart based on MenuData//from   w  ww  . ja v a2  s.c  om
 * @param dataset  a dataset
 * @return A chart suitable for rendering
 * @throws Exception 
 */
private JFreeChart createChart() throws Exception {
    XYDataset xyDataset = createDataset();
    Properties menuEventHandlerData = getAction().getMenuEventHandlerDataMap();
    String title = menuEventHandlerData.getProperty("title");
    String xAxisLabel = menuEventHandlerData.getProperty("xAxisLabel");
    String yAxisLabel = menuEventHandlerData.getProperty("yAxisLabel");
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            xAxisLabel, // x-axis label
            yAxisLabel, // y-axis label
            xyDataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    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);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    //CCHIT merge
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    // rangeAxis.setStandardTickUnits(NumberAxis.cr);
    NumberFormat formatter = new DecimalFormat("#0.00");
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setNumberFormatOverride(formatter);

    return chart;
}

From source file:kardex.graficakardex.java

public graficakardex() {
    datosxy.removeAllSeries();/*from  w w w.  jav a 2s .  c  o m*/
    //sxy.add(x[0], y[0]);
    y = new double[kardex.valor.length];
    y = kardex.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Stock de Producto", "transacciones", "cantidades",
            datosxy, PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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

From source file:entrenamiento.grafica.java

public grafica() {
    XYSeries sxy = new XYSeries("pesos");
    datosxy.removeAllSeries();//from   ww w. j a  va 2  s  .co m
    //sxy.add(x[0], y[0]);
    y = new double[Entrenamiento.valor.length];
    y = Entrenamiento.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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

From source file:entrenamiento.grafica2.java

public grafica2() {
    XYSeries sxy = new XYSeries("pesos");
    datosxy.removeAllSeries();/*from  w  ww .j av a2  s  . c  o  m*/
    //sxy.add(x[0], y[0]);
    y = new double[Entrenamiento2.valor.length];
    y = Entrenamiento2.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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

From source file:CargarEntrenamiento.grafica2.java

public grafica2() {
    datosxy.removeAllSeries();//from  w  ww.  j  ava 2s .  com
    XYSeries sxy = new XYSeries("pesos");
    //sxy.add(x[0], y[0]);
    y = new double[cargarEntreno.valorentreno.length];
    y = cargarEntreno.valorentreno;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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

From source file:vis2006.VisGrafik.java

public JFreeChart createChart(Stand st, int speciesCode) {
    // create the dataset...
    int code = speciesCode;
    int merk = 0;
    for (int i = 0; i < st.nspecies; i++)
        if (st.sp[i].code == code)
            merk = i;//  w  ww  . j av  a2s  .co m
    XYSeriesCollection dataset = new XYSeriesCollection();

    // Werte der Hhenkurve
    XYSeries series0 = new XYSeries("Hhenkurve: " + st.sp[merk].heightcurveUsed);
    for (int k = 0; k < st.ntrees; k++) {
        if ((st.tr[k].d > 0) && (st.tr[k].h > 0) && st.tr[k].code == code && st.tr[k].fac > 0.0)
            series0.add(st.tr[k].d, st.tr[k].h);
    }
    dataset.addSeries(series0);

    // Messwerte aus der Versuchsflche
    XYSeries series1 = new XYSeries("Messwerte");
    for (int k = 0; k < st.ntrees; k++) {
        if ((st.tr[k].d > 0) && (st.tr[k].hMeasuredValue > 0) && st.tr[k].code == code && st.tr[k].fac > 0.0)
            series1.add(st.tr[k].d, st.tr[k].hMeasuredValue);
    }
    dataset.addSeries(series1);

    // Andere Messwerte (HG, nurH) 
    XYSeries series2 = new XYSeries("Andere Hhen");
    for (int k = 0; k < st.ntrees; k++) {
        if ((st.tr[k].d > 0) && (st.tr[k].hMeasuredValue > 0) && st.tr[k].code == code
                && (st.tr[k].no.contains("nurH") || st.tr[k].no.contains("HG")))
            series2.add(st.tr[k].d, st.tr[k].hMeasuredValue);
    }
    dataset.addSeries(series2);

    /*   Wozu ist die gut?
         double dmin=9000;
         double dmax=-9000;
         for (int k=0;k<st.ntrees;k++){
             if (st.tr[k].code==st.sp[merk].code && st.tr[k].fac > 0.0){
    if (dmax <st.tr[k].d ) dmax=st.tr[k].d;
    if (dmin >st.tr[k].d ) dmin=st.tr[k].d;
     }
         }
            
         XYSeries series3 = new XYSeries("");
         int idmin = (int)(Math.round(dmin));
         int idmax = (int)(Math.round(dmax))+1;
         for (int k=idmin;k<=idmax;k++){
             double dwert=k*1.0;
             if (st.sp[merk].heightcurveUsed.indexOf("Einheits")>-1){
    UniformHeight uh = new UniformHeight();
    series3.add(dwert,uh.height(st.sp[merk],dwert,
                 st.sp[merk].dg,st.sp[merk].hg,st));        
             }
             else {
               HeightCurve hc =new HeightCurve(); 
               series3.add(dwert,hc.getHeight(st.sp[merk].spDef.heightCurve,dwert,st.sp[merk].heightcurveUsedP0,
                 st.sp[merk].heightcurveUsedP1,st.sp[merk].heightcurveUsedP2));
             }
           }
             dataset.addSeries(series3);
     */
    //     
    JFreeChart chart = ChartFactory.createScatterPlot("Hhenkurve  " + st.sp[merk].spDef.longName, "BHD [cm]",
            "Hhe [m]", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, //legend
            false, // tooltips
            false); // urls
    XYPlot plot = chart.getXYPlot();
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setAutoRangeMinimumSize(1.0);
    plot.getRangeAxis().setAutoRangeMinimumSize(5.0);

    //
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, true); // Hhenkurve - rote Linie
    renderer.setSeriesStroke(0, new BasicStroke(2));
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesPaint(0, Color.RED);

    renderer.setSeriesLinesVisible(1, false); // Parzellenmesswerte - blaue Symbole
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesPaint(1, Color.BLUE);

    renderer.setSeriesLinesVisible(2, false); // Andere Messwerte - blaue leere Symbole
    renderer.setSeriesShapesVisible(2, true);
    renderer.setSeriesShapesFilled(2, false);
    renderer.setSeriesPaint(2, Color.BLUE);

    //     renderer.setSeriesLinesVisible(3, true);  
    //     renderer.setSeriesShapesVisible(3,false);
    //     renderer.setSeriesPaint(3, Color.BLUE);    
    //   renderer.setSeriesPaint(1, new Color(st.sp[merk].spDef.colorRed,st.sp[merk].spDef.colorGreen,st.sp[merk].spDef.colorBlue));

    plot.setRenderer(renderer);
    System.out.println("Plot done");

    return chart;
}

From source file:atencionurgencia.evolucion.grafic_sVitales.java

private void graficar() {
    final TimeSeriesCollection dataset1 = axisTaFC.createDatasetTA();
    final JFreeChart chart2 = ChartFactory.createTimeSeriesChart("", // chart title
            "HORA", // domain axis label
            "Tensin Arterial - TA (ppm)", // range axis label
            dataset1, // data

            true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );/*from   www .  j  a  v a  2 s .  co  m*/
    chart2.setBackgroundPaint(Color.white);
    final XYPlot plot = chart2.getXYPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    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);
    }
    //        plot.set

    //        
    ////        final CategoryDataset dataset2 = axisTaFC.createDatasetFC();
    ////        plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 0);
    //        
    //        final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    //        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    ////        final ValueAxis axis2 = new NumberAxis("Frecuencia Cardiaca - FC (ppm)");
    ////        plot.setRangeAxis(1, axis2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    //        
    //        
    //        
    final ChartPanel chartPanel = new ChartPanel(chart2);
    chartPanel.setPreferredSize(new java.awt.Dimension(444, 358));//[598, 358][444, 358]
    jPanel4.removeAll();
    jPanel4.setLayout(new BorderLayout());
    jPanel4.add(chartPanel, BorderLayout.NORTH);
    jPanel4.repaint();
}