1 year ago

#365019

test-img

carloslopez

How to move a xyplot with the movement of an icon with jfreechart in java

I have an xyplot where I have an icon and several plots that you can ignore. The following picture shows the initial view of the chart.

enter image description here

The icon has movement, and does something like:

enter image description here

The icon path is more longer than this initial view, but until now I used the zoom out and zoom in in order to move myself along the path, and I would want to automate it. I would like that when the icon arrives to the middle of the x axis, the entire chart takes movement at the same time that the icon. I don't know if it's possible.

The code I think is useful:

public final class VerticalRoute {

    BufferedImage planeIcon = null;
    XYAnnotation xyannotation;
    XYPlot xyplot = null;
    JFreeChart chart = null;
    ChartPanel panel = null;

    private VerticalRoute(Trafico t) {

        try {

            planeIcon =   ImageIO.read(getClass().getClassLoader().getResource("Resources/Imagenes/lateral_avion_2.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        chart = ChartFactory.createXYLineChart("Vertical profile", "Orthodromic distance (NM)", "Altitude (ft)", this.oDataset);
        xyplot = (XYPlot) chart.getPlot();
     }

     private void updatePlaneMovement() {
             xyannotation = new XYImageAnnotation(dist_avion, alt, rotatedPlaneIcon);
             this.xyplot.addAnnotation(xyannotation);
     }
}

"dist_avion" and "alt" are the variables that are recalculated each second, and they allow the icon movement. "rotatedPlaneIcon" gives an angle in order to simulate that the "plane" is in the climb phase or in descent phase.

I tried to put an horizontal scrollbar, but as I was reading, jfreechart don't allows yet.

How can I pan the chart so it follows the movement of the icon?

java

icons

jfreechart

bufferedimage

0 Answers

Your Answer

Accepted video resources