0

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);
}
Wt Riker
  • 514
  • 12
  • 24
  • Markers and annotations stick to the plot. It looks like you want something that sticks to the enclosing panel? Please [edit] your question to include a [mcve] that exhibits the problem you describe, for [example](https://stackoverflow.com/a/44038243/230513). – trashgod Sep 29 '17 at 13:39
  • Thanks for the reply. Since this is a real time plot based on data retrieved from a specialized network device I don't know how to create the problem independently. However, it seems from your response that I am barking up the wrong tree. Are you saying that once the annotation has been plotted, even given absolute coordinates, that they will stay at that location even if the scale changes? If that is the case then I have an entirely different bug to shoot. – Wt Riker Oct 01 '17 at 11:46
  • I'm still not sure; zoom and pan this [example](https://stackoverflow.com/q/46440116/230513) or add an annotation to this [example](https://stackoverflow.com/a/44038243/230513) to see the effect. – trashgod Oct 01 '17 at 17:20

0 Answers0