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.CombinedXYPlotDemo5.java

/**
 * Creates a combined XYPlot chart.//from   ww  w .  jav  a2 s.c o m
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create a default chart based on some sample data...
    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(eur);
    dataset1.addSeries(mav);

    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    dataset2.addSeries(eur);

    JFreeChart chart = null;

    // make a common vertical axis for all the sub-plots
    final NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default

    // make a horizontally combined plot
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, new StandardXYItemRenderer());
    subplot1.setDomainCrosshairVisible(true);
    subplot1.setRangeCrosshairVisible(true);
    parent.add(subplot1, 1);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, new StandardXYItemRenderer());
    subplot2.setDomainCrosshairVisible(true);
    subplot2.setRangeCrosshairVisible(true);
    parent.add(subplot2, 1);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), null, new XYBarRenderer(0.20));
    subplot3.setDomainCrosshairVisible(true);
    subplot3.setRangeCrosshairVisible(true);
    parent.add(subplot3, 1);

    // now make the top level JFreeChart
    chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle("This is a subtitle", new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:de.iteratec.visualizationmodel.jfreechart.ChartFactory.java

public JFreeChart createXYStepChart(XYDataset dataset) {
    XYToolTipGenerator toolTipGenerator = !showTooltips ? null : new StandardXYToolTipGenerator();
    XYURLGenerator urlGenerator = !showUrls ? null : new StandardXYURLGenerator();
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, (ValueAxis) xAxis, (ValueAxis) yAxis, null);
    plot.setRenderer(renderer);//  w  w  w.  j a  v  a2s .  c  o m
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(5.0f));
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
    THEME.apply(chart);
    return chart;
}

From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitorOverlay.java

private void accumulateVisit(OurTreeNode o) throws Exception {
    this.dutYData = new ArrayList<ArrayList<Double>>();
    this.dutName = new ArrayList<String>();

    for (int i = 0; i < o.getChildCount(); i++)
        ((OurTreeNode) o.getChildAt(i)).accept(this);

    /*/* w  ww. j a  va  2  s .co m*/
     * ArrayList< Double > x = s.getXdataDefault().getXPositions(); for ( int j = 0; j < this.dutYData.size(); j++ ) {
     * ArrayList< Double > y = this.dutYData.get( j ); XYSeries xy = new XYSeries( this.dutName.get( j ) ); for ( int i =
     * 0; i < y.size(); i++ ) { xy.add( x.get( i ), y.get( i ) ); } this.xyseries.addSeries( xy ); }
     */
    NumberAxis xAxis = new NumberAxis(" X ");
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(" Y ");
    yAxis.setAutoRangeIncludesZero(false);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyseries = new XYSeriesCollection();

    XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    ExtendedJFreeChart chart = new ExtendedJFreeChart("Overlay", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    this.charts.add(chart);

}

From source file:ws.moor.bt.grapher.ChartBuilder.java

public JFreeChart getChart() {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartName, timeAxisLabel, valueAxisLabel, timeSeries,
            showLegend && (timeSeries.getSeriesCount() > 1), false, false);
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.getRenderer().setSeriesPaint(0, Color.black);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(1, Color.black);
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesPaint(2, Color.black);
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(0.1f));

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    return chart;
}

From source file:org.n52.io.img.ChartRenderer.java

private void showCrosshairsOnAxes(XYPlot xyPlot) {
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
}

From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitor.java

public void visit(Shmoo s) throws Exception {
    if (s.componentSelected(this.treePaths, OurTreeNode.MYSELF | OurTreeNode.PARENTS | OurTreeNode.CHILDS)) {
        NumberAxis xAxis = new NumberAxis(s.getTrim() + " [" + s.getXdataDefault().getUnit() + "]");
        xAxis.setAutoRangeIncludesZero(false);
        NumberAxis yAxis = new NumberAxis(
                s.getMeasure() + " [" + ((Ydata) s.getYdata().get(0)).getUnit() + "]");
        yAxis.setAutoRangeIncludesZero(false);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        this.dutData = new ArrayList<ArrayList<Double>>();
        this.dutName = new ArrayList<String>();
        for (int i = 0; i < s.getChildCount(); i++)
            (s.getChildAt(i)).accept(this);

        XYSeriesCollection xyseries = new XYSeriesCollection();
        ArrayList<Double> x = s.getXdataDefault().getXPositions();
        for (int j = 0; j < this.dutData.size(); j++) {
            ArrayList<Double> y = this.dutData.get(j);
            XYSeries xy = new XYSeries(this.dutName.get(j));
            for (int i = 0; i < y.size(); i++)
                xy.add(x.get(i), y.get(i));
            xyseries.addSeries(xy);//from w ww. j  a  v a  2  s  . c o  m
        }

        XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        Marker marker = s.getMarker();
        if (marker != null)
            plot.addRangeMarker(marker, Layer.BACKGROUND);
        ExtendedJFreeChart chart = new ExtendedJFreeChart(s.getDescription(), JFreeChart.DEFAULT_TITLE_FONT,
                plot, false);
        if (marker == null)
            chart.addSubtitle(new TextTitle(s.getSubtitle()));
        else
            chart.addSubtitle(new TextTitle(
                    s.getSubtitle() + " " + s.getValueAt(3) + "/" + s.getValueAt(4) + "/" + s.getValueAt(5)));

        chart.setTreePath(s.getTreePath());
        this.charts.add(chart);
    }

}

From source file:org.bench4Q.console.ui.section.P_WIRTSection.java

/**
 * print out a WIRT picture./*from  ww w.  j av  a  2  s  .  c o m*/
 * 
 * @return
 */
public JPanel printWIRTPic() {
    wirtCDFPrepare();
    DefaultXYDataset ds = new DefaultXYDataset();
    ds.addSeries("test", result);
    JFreeChart chart = ChartFactory.createXYLineChart("WIRT CDF", "time (ms)", "percent", ds,
            PlotOrientation.VERTICAL, false, false, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setBackgroundPaint(Color.WHITE);

    plot.setRangeCrosshairVisible(true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

From source file:chart.JChartSegment.java

/**
 * Creates a sample chart./*from  www  .j  a  v  a2 s .co m*/
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, List<NSubsequence> subsequence) {
    final JFreeChart chart = ChartFactory.createXYLineChart("Test", "Time", "Value", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    MyRender renderer = new MyRender(dataset, subsequence);
    plot.setRenderer(renderer);
    renderer.setSeriesShapesVisible(0, false);
    chart.setBackgroundPaint(Color.white);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);
    return chart;
}

From source file:MSUmpire.DIA.RTAlignedPepIonMapping.java

private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2)
        throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/"
            + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1))
            + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1))
            + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }//w ww .ja v a2 s. c o  m
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2,
            "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName),
            "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}

From source file:ch.unibe.iam.scg.archie.ui.charts.ConsultationNumberChart.java

/**
 * @see ch.unibe.iam.scg.archie.ui.charts.AbstractChartComposite#
 * initializeChart()//from ww  w .  j  av a  2s  . co m
 */
@Override
protected JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(ConsultationNumberChart.CHART_TITLE, // title
            "", // x-axis label
            "Count", // y-axis label
            (XYDataset) this.creator.getDataset(), // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(new Color(this.parent.getBackground().getRed(),
            this.parent.getBackground().getGreen(), this.parent.getBackground().getBlue()));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    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("MMM-yyyy"));

    return chart;
}