Example usage for org.jfree.ui TextAnchor HALF_ASCENT_RIGHT

List of usage examples for org.jfree.ui TextAnchor HALF_ASCENT_RIGHT

Introduction

In this page you can find the example usage for org.jfree.ui TextAnchor HALF_ASCENT_RIGHT.

Prototype

TextAnchor HALF_ASCENT_RIGHT

To view the source code for org.jfree.ui TextAnchor HALF_ASCENT_RIGHT.

Click Source Link

Document

Half-ascent/right.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart("XY Area Chart Demo", "Domain (X)", "Range (Y)",
            xydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setForegroundAlpha(0.65F);/*from  w  w w  . j a  va2  s.c  o  m*/
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setTickMarkPaint(Color.black);
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    valueaxis1.setTickMarkPaint(Color.black);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Test", 5D, -500D, 2.3561944901923448D);
    xypointerannotation.setTipRadius(0.0D);
    xypointerannotation.setBaseRadius(35D);
    xypointerannotation.setFont(new Font("SansSerif", 0, 9));
    xypointerannotation.setPaint(Color.blue);
    xypointerannotation.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    xyplot.addAnnotation(xypointerannotation);
    return jfreechart;
}

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

private TextAnchor convertStringToAnchor(String s) {
    if (s.equals("TextAnchor.TOP_LEFT"))
        return TextAnchor.TOP_LEFT;
    if (s.equals("TextAnchor.TOP_CENTER"))
        return TextAnchor.TOP_CENTER;
    if (s.equals("TextAnchor.TOP_RIGHT"))
        return TextAnchor.TOP_RIGHT;
    if (s.equals("TextAnchor.CENTER_LEFT"))
        return TextAnchor.CENTER_LEFT;
    if (s.equals("TextAnchor.CENTER"))
        return TextAnchor.CENTER;
    if (s.equals("TextAnchor.CENTER_RIGHT"))
        return TextAnchor.CENTER_RIGHT;
    if (s.equals("TextAnchor.HALF_ASCENT_LEFT"))
        return TextAnchor.HALF_ASCENT_LEFT;
    if (s.equals("TextAnchor.HALF_ASCENT_CENTER"))
        return TextAnchor.HALF_ASCENT_CENTER;
    if (s.equals("TextAnchor.HALF_ASCENT_RIGHT"))
        return TextAnchor.HALF_ASCENT_RIGHT;
    if (s.equals("TextAnchor.BASELINE_LEFT"))
        return TextAnchor.BASELINE_LEFT;
    if (s.equals("TextAnchor.BASELINE_CENTER"))
        return TextAnchor.BASELINE_CENTER;
    if (s.equals("TextAnchor.BASELINE_RIGHT"))
        return TextAnchor.BASELINE_RIGHT;
    if (s.equals("TextAnchor.BOTTOM_LEFT"))
        return TextAnchor.BOTTOM_LEFT;
    if (s.equals("TextAnchor.BOTTOM_CENTER"))
        return TextAnchor.BOTTOM_CENTER;
    if (s.equals("TextAnchor.BOTTOM_RIGHT"))
        return TextAnchor.BOTTOM_RIGHT;
    else// www .j  ava 2s .co  m
        return null;
}

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

/**
 * Creates a sample chart.//from  ww w.  j  av a  2  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:org.jfree.demo.DrawStringDemo.java

/**
 * Converts a string to a corresponding {@link TextAnchor} instance.
 *
 * @param text  the text.//from  w w w.java2  s  .c om
 *
 * @return The anchor.
 */
private TextAnchor convertStringToAnchor(final String text) {

    if (text.equals("TextAnchor.TOP_LEFT")) {
        return TextAnchor.TOP_LEFT;
    } else if (text.equals("TextAnchor.TOP_CENTER")) {
        return TextAnchor.TOP_CENTER;
    } else if (text.equals("TextAnchor.TOP_RIGHT")) {
        return TextAnchor.TOP_RIGHT;
    } else if (text.equals("TextAnchor.CENTER_LEFT")) {
        return TextAnchor.CENTER_LEFT;
    } else if (text.equals("TextAnchor.CENTER")) {
        return TextAnchor.CENTER;
    } else if (text.equals("TextAnchor.CENTER_RIGHT")) {
        return TextAnchor.CENTER_RIGHT;
    } else if (text.equals("TextAnchor.HALF_ASCENT_LEFT")) {
        return TextAnchor.HALF_ASCENT_LEFT;
    } else if (text.equals("TextAnchor.HALF_ASCENT_CENTER")) {
        return TextAnchor.HALF_ASCENT_CENTER;
    } else if (text.equals("TextAnchor.HALF_ASCENT_RIGHT")) {
        return TextAnchor.HALF_ASCENT_RIGHT;
    } else if (text.equals("TextAnchor.BASELINE_LEFT")) {
        return TextAnchor.BASELINE_LEFT;
    } else if (text.equals("TextAnchor.BASELINE_CENTER")) {
        return TextAnchor.BASELINE_CENTER;
    } else if (text.equals("TextAnchor.BASELINE_RIGHT")) {
        return TextAnchor.BASELINE_RIGHT;
    } else if (text.equals("TextAnchor.BOTTOM_LEFT")) {
        return TextAnchor.BOTTOM_LEFT;
    } else if (text.equals("TextAnchor.BOTTOM_CENTER")) {
        return TextAnchor.BOTTOM_CENTER;
    } else if (text.equals("TextAnchor.BOTTOM_RIGHT")) {
        return TextAnchor.BOTTOM_RIGHT;
    } else {
        return null;
    }

}

From source file:umontreal.ssj.charts.XYChart.java

/**
 * Draws a vertical line on the chart at @f$x@f$-coordinate `x`. `name`
 * is written near the line at @f$y@f$ position `yfrac` (a fraction of
 * the @f$y@f$-size of the chart, 0 is the bottom, 1 is the top); if
 * `right` is `true`, `name` is written on the right of the line, else
 * on the left./*from ww  w  .  j  a v a  2  s .  com*/
 *  @param x            @f$x@f$-coordinate of the line
 *  @param name         description of the line
 *  @param yfrac        @f$y@f$-position of name
 *  @param right        @f$x@f$-position of name
 */
public void drawVerticalLine(double x, String name, double yfrac, boolean right) {
    double ybottom = YAxis.getAxis().getLowerBound();
    final Object o = this;
    if (this instanceof HistogramChart)
        ybottom = 0;
    double ytop = YAxis.getAxis().getUpperBound();
    XYLineAnnotation line = new XYLineAnnotation(x, ybottom, x, ytop);
    XYTextAnnotation text = new XYTextAnnotation(name, x, ytop * yfrac);
    if (!right)
        text.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    else
        text.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    XYPlot plot = getJFreeChart().getXYPlot();
    plot.addAnnotation(line);
    plot.addAnnotation(text);
}

From source file:com.sdk.connector.chart.TimeDomainRenderer.java

public void createAnnotation(String lap, double x, double y) {

    final CircleDrawer cd = new CircleDrawer(Color.GREEN, new BasicStroke(1.0f), null);
    final XYAnnotation lapLabel = new XYDrawableAnnotation(x, y, 15, 15, cd);
    lapAnnotations.add(lapLabel);/*from   w w w. ja  v  a2s .c om*/
    plot.addAnnotation(lapAnnotations.lastElement(), false);
    final XYPointerAnnotation pointer = new XYPointerAnnotation(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("label.lap") + lap,
            x, y, 345);
    pointer.setBaseRadius(35.0);
    pointer.setTipRadius(10.0);
    pointer.setFont(new Font("DejaVu Sans", Font.BOLD, 11));
    pointer.setPaint(Color.black);
    pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    lapAnnotations.add(pointer);
    plot.addAnnotation(lapAnnotations.lastElement(), false);
}

From source file:adapters.XYChartAdapter.java

/**
 * Draws a vertical line on the chart at <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinate <TT>x</TT>.
 * <TT>name</TT> is written near the line at <SPAN CLASS="MATH"><I>y</I></SPAN> position <TT>yfrac</TT>
 * (a fraction of the <SPAN CLASS="MATH"><I>y</I></SPAN>-size of the chart, 0 is the bottom, 1 is the top);
 * if <TT>right</TT> is <TT>true</TT>, <TT>name</TT> is written on the right
 * of the line, else on the left.//from   w w  w .  j ava2s. c o m
 *
 * @param x <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinate of the line
 *
 *    @param name description of the line
 *
 *    @param yfrac <SPAN CLASS="MATH"><I>y</I></SPAN>-position of name
 *
 *    @param right <SPAN CLASS="MATH"><I>x</I></SPAN>-position of name
 *
 */
public void drawVerticalLine(double x, String name, double yfrac, boolean right) {
    double ybottom = YAxis.getAxis().getLowerBound();
    final Object o = this;
    if (this instanceof HistogramChartAdapter)
        ybottom = 0;
    double ytop = YAxis.getAxis().getUpperBound();
    XYLineAnnotation line = new XYLineAnnotation(x, ybottom, x, ytop);
    XYTextAnnotation text = new XYTextAnnotation(name, x, ytop * yfrac);
    if (!right)
        text.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    else
        text.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    XYPlot plot = getJFreeChart().getXYPlot();
    plot.addAnnotation(line);
    plot.addAnnotation(text);
}

From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java

public void createAnnotation(Color color, double lap, double x, double y) {

    final XYPointerAnnotation pointer = new XYPointerAnnotation("", x, y, 345);
    pointer.setBaseRadius(35.0);/* w  w w. ja v  a 2 s  .c o  m*/
    pointer.setTipRadius(5.0);
    pointer.setFont(new Font("DejaVu Sans", Font.PLAIN, 9));
    pointer.setPaint(Color.blue);
    pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
    lapAnnotations.add(pointer);
    renderer.addAnnotation(lapAnnotations.lastElement());

    chartPanel.repaint();
    chartPanel.revalidate();
}