I have a realtime time series chart where I add vertical value markers when certain events occur. I want to also label those markers with XYTextAnnotation (also vertically). I tried to locate the label along the right side and top of the marker. However, the Y axis of chart uses AutoRange but the annotation is in an absolute X,Y location. The result is that it moves off the chart in the Y axis and disappears as the range increases. How can I add the label so it stays on the chart relative to the changing range? TIA.
Here is my current code:
public void addMarker(String id_,String name_) {
Functions.logger("Adding open door marker for "+id_+" "+name_,false);
Long tod=new Date().getTime();
ValueMarker marker=new ValueMarker(tod);
XYTextAnnotation label=new XYTextAnnotation("Door Open: "+name_,tod-1,360);
label.setRotationAnchor(TextAnchor.BASELINE_CENTER);
label.setTextAnchor(TextAnchor.BASELINE_CENTER);
label.setRotationAngle(-Math.PI/2);
label.setPaint(Color.BLACK);
marker.setStroke(new BasicStroke(2));
marker.setPaint(Color.BLACK);
chart.addDomainMarker(marker);
chart.addAnnotation(label);
}