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

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

Introduction

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

Prototype

public void setLabelAnchor(RectangleAnchor anchor) 

Source Link

Document

Sets the label anchor and sends a MarkerChangeEvent to all registered listeners.

Usage

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

public static ChartPanel buildGapChartPanel(final Instances dataSet, final int dateIdx, final Attribute attr,
        final int gapsize, final int position) throws Exception {
    Instances filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet,
            new int[] { attr.index(), dateIdx });
    filteredDs = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs, 0, filteredDs.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDs.numInstances() - 1));

    final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(filteredDs, false,
            WekaDataStatsUtil.getFirstDateAttributeIdx(filteredDs), null);

    final XYPlot xyp = (XYPlot) cp.getChart().getPlot();
    xyp.getDomainAxis().setLabel("");
    xyp.getRangeAxis().setLabel("");

    final Marker gapBeginMarker = new ValueMarker(dataSet.instance(Math.max(0, position - 1)).value(dateIdx));
    gapBeginMarker.setPaint(Color.RED);
    gapBeginMarker.setLabel("Gap begin");
    gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

    final Marker gapEndMarker = new ValueMarker(
            dataSet.instance(Math.min(dataSet.numInstances() - 1, position + gapsize)).value(dateIdx));
    gapEndMarker.setPaint(Color.RED);
    gapEndMarker.setLabel("Gap end");
    gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

    addExportPopupMenu(filteredDs, cp);/*from  w w  w  . ja v a 2  s.c  o  m*/

    return cp;
}

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection tempChrData, boolean showlables) {
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesVisibleInLegend(0, showlables);
    renderer.setSeriesVisibleInLegend(1, showlables);
    //renderer.setBaseShape(new Ellipse2D.Float(0, 0, 2,2), false);

    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);/*from   www  .  j  a  v a2 s .co m*/
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setAutoRangeMinimumSize(0.0000005);
        rangeAxis.setLowerBound(1d);
        //rangeAxis.setAutoRangeIncludesZero(false);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", tempChrData,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    final Marker thresholdLine = new ValueMarker(0.0000005);
    thresholdLine.setPaint(Color.red);
    if (showlables) {
        thresholdLine.setLabel("P = 510??");
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(false);
    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    chrAxis.setAutoRangeIncludesZero(false);
    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx,
        final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller,
        final java.util.Collection<String> attrs) throws Exception {
    final Instances dataSetWithTheGap = new Instances(pdataSet);
    for (int i = position; i < position + gapsize; i++)
        dataSetWithTheGap.instance(i).setMissing(attr);

    int[] arr = new int[] { attr.index(), dateIdx };
    for (final String sss : attrs) {
        arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() });
    }//from  w w  w  .  j a  v  a 2s .  c o m

    Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap,
            arr);
    filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0,
            filteredDsWithTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithTheGap.numInstances() - 1));

    final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap);
    final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds);

    Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr);
    filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0,
            filteredDsWithoutTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithoutTheGap.numInstances() - 1));

    diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes());
    for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) {
        diff.instance(i).setValue(diff.numAttributes() - 1,
                filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name())));
    }
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final java.util.List<String> toRemove = new java.util.ArrayList<String>();
    for (int j = 0; j < diff.numAttributes(); j++) {
        final String consideredAttrName = diff.attribute(j).name();
        if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name()))
            toRemove.add(consideredAttrName);
    }
    diff.setClassIndex(-1);
    for (final String ssss : toRemove)
        diff.deleteAttributeAt(diff.attribute(ssss).index());
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false,
            WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null);

    final XYPlot xyp = (XYPlot) cp.getChart().getPlot();
    xyp.getDomainAxis().setLabel("");
    xyp.getRangeAxis().setLabel("");

    final Marker gapBeginMarker = new ValueMarker(
            dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx));
    gapBeginMarker.setPaint(Color.RED);
    gapBeginMarker.setLabel("Gap begin");
    gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

    final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap
            .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx));
    gapEndMarker.setPaint(Color.RED);
    gapEndMarker.setLabel("Gap end");
    gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

    addExportPopupMenu(diff, cp);

    return cp;
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background,
        Color backgroundAlternative, Color main) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    // Set dot shape of the currently appended Series
    renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main);
    renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables);
    renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    // Set range axis
    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);//from w w  w . j  ava 2  s  .co  m
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setUpperMargin(0);

        TickUnitSource units = NumberAxis.createIntegerTickUnits();
        rangeAxis.setStandardTickUnits(units);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    // Build subchart
    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC,
            PlotOrientation.VERTICAL, false, false, false);

    // Get subplot from subchart
    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    // CHART BACKGROUD COLOR
    if (combinedPlot.getSubplots().size() % 2 == 0) {
        subplot.setBackgroundPaint(background); // Hue, saturation, brightness
    } else {
        subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness
    }

    // Add significance Threshold to subplot
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to hetzyThreshold
    if (showlables) {
        thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold));
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    // Chromosome Axis Labels
    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setLabelAngle(1.0);
    chrAxis.setAutoRangeIncludesZero(false);
    chrAxis.setAxisLineVisible(true);

    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    //      chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC);
    //      TickUnitSource units = NumberAxis.createIntegerTickUnits();
    //      chrAxis.setStandardTickUnits(units);

    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:org.sonar.server.charts.jruby.TrendsChart.java

public void addLabel(Date date, String label, boolean lower) throws ParseException {
    Day d = new Day(date);
    double millis = d.getFirstMillisecond();
    Marker marker = new ValueMarker(millis);
    marker.setLabel(label);/*from   w  w w. ja  va 2s. c o m*/
    marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    Color c = new Color(17, 40, 95);
    marker.setLabelPaint(c);
    marker.setPaint(c);
    marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3.0f,
            new float[] { 5f, 5f, 5f, 5f }, 2.0f));
    if (lower) {
        marker.setLabelOffset(new RectangleInsets(18, 0, 0, 5));
    }
    plot.addDomainMarker(marker);
}

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);
    }//  ww  w . ja  v a 2s  . c o  m
}

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

/**
 * Creates a sample chart.//  www  . j  a  v  a2 s . c  o  m
 *
 * @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:ui.Graph.java

/**
 * Creates a chart./*from www  .  ja va2 s .  com*/
 *
 * @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: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 {//from  w w w  .j av  a2 s .  c  om
            target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
            target.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        }
        plot.addDomainMarker(target);
    }
}

From source file:net.sf.jasperreports.customizers.marker.AbstractMarkerCustomizer.java

protected void configureMarker(Marker marker) {
    String label = getProperty(PROPERTY_LABEL);
    if (label != null && label.length() > 0) {
        marker.setLabel(label);// w  w w  .  j  a v  a  2  s.  c o m
    }

    RectangleAnchorEnum labelAnchor = RectangleAnchorEnum.getByName(getProperty(PROPERTY_LABEL_ANCHOR));
    if (labelAnchor != null) {
        marker.setLabelAnchor(labelAnchor.getRectangleAnchor());
    }

    Double offsetTop = getDoubleProperty(PROPERTY_LABEL_OFFSET_TOP);
    Double offsetLeft = getDoubleProperty(PROPERTY_LABEL_OFFSET_LEFT);
    Double offsetBottom = getDoubleProperty(PROPERTY_LABEL_OFFSET_BOTTOM);
    Double offsetRight = getDoubleProperty(PROPERTY_LABEL_OFFSET_RIGHT);
    if (offsetTop != null || offsetLeft != null || offsetBottom != null || offsetRight != null) {
        RectangleInsets currentOffset = marker.getLabelOffset();
        marker.setLabelOffset(new RectangleInsets(offsetTop == null ? currentOffset.getTop() : offsetTop,
                offsetLeft == null ? currentOffset.getLeft() : offsetLeft,
                offsetBottom == null ? currentOffset.getBottom() : offsetBottom,
                offsetRight == null ? currentOffset.getRight() : offsetRight));
    }

    TextAnchorEnum labelTextAnchor = TextAnchorEnum.getByName(getProperty(PROPERTY_LABEL_TEXT_ANCHOR));
    if (labelTextAnchor != null) {
        marker.setLabelTextAnchor(labelTextAnchor.getTextAnchor());
    }

    Color color = JRColorUtil.getColor(getProperty(PROPERTY_COLOR), null);
    if (color != null) {
        marker.setPaint(color);
    }

    Float alpha = getFloatProperty(PROPERTY_ALPHA);
    if (alpha != null) {
        marker.setAlpha(alpha);
    }
}