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

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

Introduction

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

Prototype

public void addDomainMarker(Marker marker) 

Source Link

Document

Adds a marker for the domain axis and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.TimeSeriesPlot.java

@Override
protected void applyRendering(XYPlot plot) {
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(StringUtility.getDateFormat());

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesPaint(0, DATA_COLOR);

    if (m_markerTimestamp > 0) {
        final Marker target = new ValueMarker(m_markerTimestamp);
        target.setPaint(Color.RED);
        target.setLabel("Short Term");
        if ((m_markerPosition * 2) > getDatasetSize()) {
            //Move the label to the left of the marker
            target.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        } else {/*  ww  w  .j ava2s  .c om*/
            target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
            target.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        }
        plot.addDomainMarker(target);
    }
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java

public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    // if (this.decoratedChart instanceof TimeChartRenderer ) {

    if (this.results != null && !this.results.isEmpty()) {
        Iterator iter1 = this.results.iterator();
        ValueMarker valuemarker = null;//from  w w w.  j  a  v a  2 s. co m
        BlockContainer blockcontainerLabel = new BlockContainer(new ColumnArrangement());
        // blockcontainerLabel.setFrame( new LineBorder() );
        int i = 0;
        while (iter1.hasNext()) {
            Object[] item = (Object[]) iter1.next();
            Date date = (Date) item[1];
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            valuemarker = new ValueMarker(cal.getTimeInMillis(), ChartColor.createDefaultPaintArray()[i],
                    new BasicStroke(2.0F));

            xyplot.addDomainMarker(valuemarker);
            LegendItem legendLabel = new LegendItem((String) item[0], null, null, null,
                    new Line2D.Double(-7.0, 0.0, 7.0, 0.0), valuemarker.getPaint(), valuemarker.getStroke(),
                    valuemarker.getPaint());

            blockcontainerLabel.add(createLegendItemBlock(legendLabel, i));
            i++;
        }
        createLegendBlock(blockcontainerLabel);
    }
    // }
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

private void chartDrawVerticalLine(VACVBSMetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(data.date1.getTime());
    start.setPaint(color);//w  w  w .j  av  a2s.  c om
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addDomainMarker(start);
}

From source file:jboost.visualization.HistogramFrame.java

private JFreeChart createRocChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("ROC", // chart title
            "False positive rate", // x axis label
            "True positive rate", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include
            // legend
            true, // tooltips
            false // urls
    );//from   w w  w.  ja v a2  s  .  c o  m

    chart.setAntiAlias(false);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    chart.setRenderingHints(hints);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    lower_tprMarker = new ValueMarker(0.5);
    lower_tprMarker.setPaint(Color.blue);
    lower_fprMarker = new ValueMarker(0.5);
    lower_fprMarker.setPaint(Color.blue);
    plot.addRangeMarker(lower_tprMarker);
    plot.addDomainMarker(lower_fprMarker);

    upper_tprMarker = new ValueMarker(0.5);
    upper_tprMarker.setPaint(Color.red);
    upper_fprMarker = new ValueMarker(0.5);
    upper_fprMarker.setPaint(Color.red);
    plot.addRangeMarker(upper_tprMarker);
    plot.addDomainMarker(upper_fprMarker);

    return chart;

}

From source file:ec.ui.view.StabilityView.java

private void configureAxis(XYPlot plot) {
    int nb = graphs_.size();
    List<String> names = new ArrayList<>();
    for (Map.Entry<Bornes, Graphs> entry : graphs_.entrySet()) {
        names.add(entry.getValue().label_);
    }//  ww w .j  a v a2 s  . c  o m

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelPaint(Color.GRAY);
    xAxis.setTickUnit(new StabilityTickUnit(names));
    xAxis.setRange(-0.5, nb - 0.5);
    plot.setDomainAxis(xAxis);
    plot.setDomainGridlinesVisible(false);
    NumberAxis yaxis = new NumberAxis();
    rescaleAxis(yaxis);
    plot.setRangeAxis(yaxis);

    for (int i = 0; i < nb; i++) {
        ValueMarker marker = new ValueMarker(i + 0.5);
        marker.setStroke(MARKER_STROKE);
        marker.setPaint(MARKER_PAINT);
        marker.setAlpha(MARKER_ALPHA);
        plot.addDomainMarker(marker);
    }
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

private void chartDrawVerticalLine(W3330MetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(data.time.getTime());
    start.setPaint(color);//  w w w . ja v  a  2s  . co m
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addDomainMarker(start);
}

From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java

private void configureAxis(XYPlot plot, int start, int end) {
    int nb = graphs_.size();
    List<String> names = new ArrayList<>();
    for (int i = start; i <= end; i++) {
        names.add(periods.get(i).toString());
    }/*from w w w .java2  s.  com*/

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelPaint(Color.GRAY);
    xAxis.setTickUnit(new MyTickUnit(names));
    xAxis.setRange(-0.5, nb - 0.5);
    xAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(xAxis);
    plot.setDomainGridlinesVisible(false);
    NumberAxis yaxis = new NumberAxis();
    rescaleAxis(yaxis);
    yaxis.configure();
    plot.setRangeAxis(yaxis);

    for (int i = 0; i < nb; i++) {
        ValueMarker marker = new ValueMarker(i + 0.5);
        marker.setStroke(MARKER_STROKE);
        marker.setPaint(MARKER_PAINT);
        marker.setAlpha(MARKER_ALPHA);
        plot.addDomainMarker(marker);
    }
}

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

/**
 * Creates a sample chart./*from  w  ww .  j  av  a 2s  .c  om*/
 *
 * @param data  the sample data.
 *
 * @return A configured chart.
 */
private JFreeChart createChart(final XYDataset data) {

    final JFreeChart chart = ChartFactory.createScatterPlot("Marker Demo 1", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    //    chart.getLegend().setAnchor(Legend.EAST);

    // customise...
    final XYPlot plot = chart.getXYPlot();
    plot.getRenderer().setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    // set axis margins to allow space for marker labels...
    final DateAxis domainAxis = new DateAxis("Time");
    domainAxis.setUpperMargin(0.50);
    plot.setDomainAxis(domainAxis);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.30);
    rangeAxis.setLowerMargin(0.50);

    // add a labelled marker for the bid start price...
    final Marker start = new ValueMarker(200.0);
    start.setPaint(Color.green);
    start.setLabel("Bid Start Price");
    start.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
    start.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    plot.addRangeMarker(start);

    // add a labelled marker for the target price...
    final Marker target = new ValueMarker(175.0);
    target.setPaint(Color.red);
    target.setLabel("Target Price");
    target.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    plot.addRangeMarker(target);

    // add a labelled marker for the original closing time...
    final Hour hour = new Hour(2, new Day(22, 5, 2003));
    double millis = hour.getFirstMillisecond();
    final Marker originalEnd = new ValueMarker(millis);
    originalEnd.setPaint(Color.orange);
    originalEnd.setLabel("Original Close (02:00)");
    originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    plot.addDomainMarker(originalEnd);

    // add a labelled marker for the current closing time...
    final Minute min = new Minute(15, hour);
    millis = min.getFirstMillisecond();
    final Marker currentEnd = new ValueMarker(millis);
    currentEnd.setPaint(Color.red);
    currentEnd.setLabel("Close Date (02:15)");
    currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addDomainMarker(currentEnd);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // label the best bid with an arrow and label...
    final Hour h = new Hour(2, new Day(22, 5, 2003));
    final Minute m = new Minute(10, h);
    millis = m.getFirstMillisecond();
    final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
    final XYAnnotation bestBid = new XYDrawableAnnotation(millis, 163.0, 11, 11, cd);
    plot.addAnnotation(bestBid);
    final XYPointerAnnotation pointer = new XYPointerAnnotation("Best Bid", millis, 163.0, 3.0 * Math.PI / 4.0);
    pointer.setBaseRadius(35.0);
    pointer.setTipRadius(10.0);
    pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
    pointer.setPaint(Color.blue);
    pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    plot.addAnnotation(pointer);

    return chart;

}

From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java

private void setEndAnnotation() {
    XYPlot plot = ((XYPlot) chart.getPlot());
    double x = plot.getDomainCrosshairValue();
    if (endPointer != null) {
        plot.removeDomainMarker(endPointer);
    }/*  w w w  .  j a v  a 2  s  .  co  m*/

    if (endPointer != null && endPointer.getValue() == x) {
        plot.removeDomainMarker(endPointer);
        endPointer = null;
    } else {
        if (startPointer != null) {
            if (startPointer.getValue() > x) {
                //flip start and end
                plot.removeDomainMarker(startPointer);
                endPointer = new ValueMarker(startPointer.getValue());
                endPointer.setLabel("Ende");
                endPointer.setPaint(Color.red);
                plot.addDomainMarker(endPointer);
                startPointer = new ValueMarker(x);
                startPointer.setLabel("Start");
                startPointer.setPaint(Color.green);
                plot.addDomainMarker(startPointer);
            } else {
                endPointer = new ValueMarker(x);
                endPointer.setLabel("Ende");
                endPointer.setPaint(Color.red);
                plot.addDomainMarker(endPointer);
            }
        } else {
            endPointer = new ValueMarker(x);
            endPointer.setLabel("Ende");
            endPointer.setPaint(Color.red);
            plot.addDomainMarker(endPointer);
        }
    }

    jChartPanel.repaint();
}

From source file:ui.Graph.java

/**
 * Creates a chart./*from  w ww. java  2s  . c om*/
 *
 * @param dataset
 *            the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(ArrayList<Setpoint> setpoints, ArrayList<Setpoint> traj) {
    trajectory = traj;

    XYSeries posSeries = new XYSeries("Position");
    XYSeries trajSeries = new XYSeries("Trajectory");
    XYSeries velSeries = new XYSeries("Velocity");
    for (int i = 0; i < setpoints.size(); i++) {

        Setpoint p = setpoints.get(i);
        posSeries.add(p.time, p.position);
        velSeries.add(p.time, p.velocity);
    }

    for (int i = 0; i < trajectory.size(); i++) {

        Setpoint p = trajectory.get(i);
        trajSeries.add(p.time, p.position);

    }

    XYSeriesCollection posDataset = new XYSeriesCollection();
    XYSeriesCollection trajDataset = new XYSeriesCollection();
    XYSeriesCollection velDataset = new XYSeriesCollection();

    posDataset.addSeries(posSeries);
    velDataset.addSeries(velSeries);
    trajDataset.addSeries(trajSeries);
    // create the chart...
    final JFreeChart chart = ChartFactory.createScatterPlot("System output", // chart title
            "X", // x axis label
            "Y", // y axis label
            posDataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();

    plot.setDataset(0, posDataset);
    plot.setDataset(1, trajDataset);
    plot.setDataset(2, velDataset);
    plot.setBackgroundPaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer posRenderer = new XYLineAndShapeRenderer();
    // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f,
    // 1.0f));
    posRenderer.setSeriesPaint(0, Color.BLUE);
    posRenderer.setSeriesLinesVisible(0, true);
    posRenderer.setSeriesShapesVisible(0, false);
    XYStepRenderer trajRenderer = new XYStepRenderer();
    trajRenderer.setSeriesPaint(1, Color.RED);
    trajRenderer.setSeriesStroke(1, new BasicStroke(10));
    trajRenderer.setSeriesLinesVisible(1, true);
    trajRenderer.setSeriesShapesVisible(1, false);

    XYLineAndShapeRenderer velRenderer = new XYLineAndShapeRenderer();
    velRenderer.setSeriesPaint(0, Color.MAGENTA);
    velRenderer.setSeriesLinesVisible(0, true);
    velRenderer.setSeriesShapesVisible(0, false);
    // renderer.setSeriesStroke(1, new BasicStroke(0.01f));
    plot.setRenderer(0, posRenderer);
    plot.setRenderer(1, trajRenderer);
    plot.setRenderer(2, velRenderer);

    for (Setpoint s : trajectory) {
        Marker marker = new ValueMarker(s.time);
        marker.setPaint(Color.DARK_GRAY);
        marker.setLabel(Float.toString((float) s.position));
        marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(marker);
    }

    XYTextAnnotation p = new XYTextAnnotation("kP = " + gains.kP, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .75);
    p.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(p);
    XYTextAnnotation i = new XYTextAnnotation("kI = " + gains.kI, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .7);
    i.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(i);
    XYTextAnnotation d = new XYTextAnnotation("kD = " + gains.kD, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .65);
    d.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(d);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}