A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
shethab
- Posts: 5
- Joined: Wed Sep 30, 2015 9:23 pm
- antibot: No, of course not.
Post
by shethab » Wed Sep 30, 2015 9:32 pm
I have a XYPlot. In the ChartPanel i have added a ChartMouseListener.
Code: Select all
// mouse listener
chartPanel.addChartMouseListener(new ChartMouseListener() {<implemented methods>});
I have added a a couple of markers to the chart.
Code: Select all
final Marker tempMarker = new ValueMarker(hour.getFirstMillisecond());
tempMarker.setLabel("Event Name");
tempMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
tempMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
plot.addDomainMarker(tempMarker);
I want to capture when the mouse goes over the markers.
I have done a bunch of reading and the CharMouseListener only triggers when mouse goes over an Entity. How can i make the ValueMarker an entity so ChartMouseListener knows when i mouse over it.
-
paradoxoff
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Post
by paradoxoff » Thu Oct 01, 2015 12:06 pm
Short answer: you can´t, unless you changed a couple of JFreeChart classes.
See
this thread with a couple of annotation classes that do the same job as a marker.
-
shethab
- Posts: 5
- Joined: Wed Sep 30, 2015 9:23 pm
- antibot: No, of course not.
Post
by shethab » Thu Oct 01, 2015 7:57 pm
ok i implemented the annotation classes you pointed to.
I now have the annotations showing. How do i capture the mouseOver event now?
Code: Select all
private void formEventAnnotations(XYPlot plot, Hour hour, int priority) {
try {
final XYDomainValueAnnotation tempMarker = new XYDomainValueAnnotation();
switch (priority) {
case Constants.HIGH_IMPORTANCE:
tempMarker.setPaint(Color.RED);
break;
case Constants.LOW_IMPORTANCE:
tempMarker.setPaint(Color.GREEN);
break;
default:
tempMarker.setPaint(Color.BLACK);
}
tempMarker.setLabel("Event Name");
tempMarker.setStroke(new BasicStroke(5.0f));
tempMarker.setValue(hour.getFirstMillisecond());
tempMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
tempMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
tempMarker.setRotationAnchor(TextAnchor.TOP_LEFT);
plot.addAnnotation(tempMarker);
} catch (Exception e) {
e.printStackTrace();
}
}
I setup a `chartMouseListener` but when i mouse over the annotations nothing really happens. (i have a println printing out the event.entity )
-
shethab
- Posts: 5
- Joined: Wed Sep 30, 2015 9:23 pm
- antibot: No, of course not.
Post
by shethab » Thu Oct 01, 2015 8:02 pm
Got it. My Bad.
added this line
Code: Select all
tempMarker.setToolTipText("Event Name");
-
shethab
- Posts: 5
- Joined: Wed Sep 30, 2015 9:23 pm
- antibot: No, of course not.
Post
by shethab » Thu Oct 01, 2015 8:23 pm
Only issues is how do i get it to paint the annotation lines behind the series lines?