Line Annotation does not draw

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

Line Annotation does not draw

Postby blahfunk » Wed Feb 21, 2018 5:51 pm

I have created an XYLineAnnotation object to draw a line into my graph, but it doesn't draw? I am using a ChartMouseListener so that it will follow the mouse pointer like so:

Code: Select all
someChartPanel.addChartMouseListener(new ChartMouseListener() {
    private int lineLoc = 0;
    private XYLineAnnotation line = null;
    public void chartMouseClicked(ChartMouseEvent e) {}
    public void chartMouseMoved(ChartMouseEvent e) {
        lineLoc = e.getTrigger().getX();
        if (line != null) someChartPanel.getChart().getXYPlot().removeAnnotation(line);
        line = new XYLineAnnotation(lineLoc, 0, lineLoc, 1000, new BasicStroke(1.5f), Color.RED);
        System.out.println(lineLoc); // This works!!!

.. but it never draws. Notice in my code that I put a println just to see if the code is even being executed and the println does execute. What is happening and how do I get the line to draw over my chart?
Posts: 5
Joined: Wed Jan 17, 2018 5:52 pm

Re: Line Annotation does not draw

Postby david.gilbert » Thu Feb 22, 2018 6:24 am

The coordinates that you pass to the XYLineAnnotation constructor need to be specified in data space (that is, values relative to the chart's axes) not in screen space.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
JFreeChart Project Leader
Posts: 11664
Joined: Fri Mar 14, 2003 10:29 am

Return to JFreeChart

Who is online

Users browsing this forum: Google [Bot] and 7 guests