Example usage for org.jfree.chart.plot Marker setPaint

List of usage examples for org.jfree.chart.plot Marker setPaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot Marker setPaint.

Prototype

public void setPaint(Paint paint) 

Source Link

Document

Sets the paint and sends a MarkerChangeEvent to all registered listeners.

Usage

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

/**
 * A demonstration application showing a quarterly time series containing a null value.
 *
 * @param title  the frame title.//from w w  w . j  a  v a  2 s  . com
 */
public TimeSeriesDemo4(final String title) {

    super(title);
    final TimeSeries series = new TimeSeries("Random Data", Hour.class);
    final Day today = new Day();
    series.add(new Hour(1, today), 500.2);
    series.add(new Hour(2, today), 694.1);
    series.add(new Hour(3, today), 734.4);
    series.add(new Hour(4, today), 453.2);
    series.add(new Hour(7, today), 500.2);
    series.add(new Hour(8, today), null);
    series.add(new Hour(12, today), 734.4);
    series.add(new Hour(16, today), 453.2);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(series);

    // create a title with Unicode characters (currency symbols in this case)...
    final String chartTitle = "\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA";
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Value", dataset, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    //      plot.setInsets(new Insets(0, 0, 0, 20));
    final Marker marker = new ValueMarker(700.0);
    marker.setPaint(Color.blue);
    marker.setAlpha(0.8f);
    plot.addRangeMarker(marker);
    plot.setBackgroundPaint(null);
    plot.setBackgroundImage(JFreeChart.INFO.getLogo());
    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        r.setPlotShapes(true);
        r.setShapesFilled(true);
    }
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

From source file:biz.ixnay.pivot.charts.skin.jfree.HistogramViewSkin.java

private void createMarkers(JFreeChart chart, ChartView chartView) {
    for (org.apache.pivot.charts.content.ValueMarker valueMarker : chartView.getValueMarkers()) {
        final Marker target = new ValueMarker(valueMarker.getValue());
        target.setPaint(valueMarker.getColor());
        target.setLabel(valueMarker.getLabel());
        target.setLabelAnchor(RectangleAnchor.TOP);
        target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        ((XYPlot) chart.getPlot()).addDomainMarker(target);
    }//from ww w  .  j  a v a  2  s  . co m
}

From source file:graph_line.java

public void addMarkers(double peak) {
    if (_active > 0) {
        Marker m1 = new ValueMarker(peak);
        m1.setStroke(new BasicStroke((float) .5));
        m1.setPaint(Color.GRAY);
        plot.addDomainMarker(m1);//from  w w w. j a  v  a  2  s. com
    }
}

From source file:graph_baseband.java

public void addMarkers(double peak, Color color) {
    if (_active > 0) {
        Marker m1 = new ValueMarker(peak);
        m1.setStroke(new BasicStroke((float) 1));
        m1.setPaint(color);
        plot.addDomainMarker(m1);/*  w w w. j a  va  2s .  c  o  m*/
    }
}

From source file:graph_line.java

public void addMarkers(double[] peak) {
    if (_active > 0) {
        for (int i = 0; i < peak.length; i++) {
            Marker m1 = new ValueMarker(peak[i]);
            m1.setStroke(new BasicStroke((float) .5));
            m1.setPaint(Color.GRAY);
            plot.addDomainMarker(m1);//from w w  w  .j  av a2  s  .c  om
        }
    }
}

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 .jav a2s  .  c  om*/
            target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
            target.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        }
        plot.addDomainMarker(target);
    }
}

From source file:ui.Graph.java

/**
 * Creates a chart.//from   ww  w  .j ava 2  s.c o m
 *
 * @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;

}

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

/**
 * Creates a sample chart./*  w  w w .j a v a2s  . 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:graph_line.java

public void addMarkers(double pos1, double pos2) {
    if (!fftseries.isEmpty()) {
        Marker m1 = new ValueMarker(pos1);
        Marker m2 = new ValueMarker(pos2);

        m1.setStroke(new BasicStroke(2));
        m2.setStroke(new BasicStroke(2));
        m1.setPaint(Color.RED);
        m2.setPaint(Color.GREEN);
        plot.addDomainMarker(m1);//from w  ww .jav a2 s. c om
        plot.addDomainMarker(m2);
    }

}

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

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYItemRenderer renderer = plot.getRenderer();
    KnownColor color = ACKind.Normal == kind ? NORMAL_COLOR : PARTIAL_COLOR;
    renderer.setBasePaint(themeSupport.getAreaColor(color));
    renderer.setBaseOutlinePaint(themeSupport.getLineColor(color));

    Collection<Marker> markers = (Collection<Marker>) plot.getDomainMarkers(Layer.FOREGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(markers)) {
        Color markerColor = themeSupport.getLineColor(MARKER_COLOR);
        for (Marker o : markers) {
            o.setPaint(markerColor);
        }//w ww .j av  a2 s . c  o m
    }
}