Hi Friends,
I have been searching the ChartMouseEvent. I haven't found any reference to this situation.
Say you have a TimeSeries graph. You click on one of the lines in the chart. Can you get the desciption of that line?
For example, you add a CharMouseEvent to TimeSeriesDemo3. You click on the line for "Series 1". Can you get the "Series 1" value?
If this is not possible, please let me know as well so I can go at it at a different angle.
Thanks.
Can ChartMouseEvent return the description of a TimeSeries
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
At the moment, the XYLineAndShapeRenderer will create a ChartEntity for the end point of the line. So if you click on the data point, you'll get a ChartEntity back. But if you click in the middle of the line, there is no entity defined for the line. What's needed is a modification to the renderer that creates a "hotspot" for the line as well as the data point...it's on the to-do list, Patches are welcome, as usual...
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Since I'm the type that likes to see the code, I'll post what I did using David's tip.
This works nicely for what I need.
-----------start---------------------
public void chartMouseClicked(ChartMouseEvent event)
{
int mouseX = event.getTrigger().getX();
int mouseY = event.getTrigger().getY();
Point2D p = chartPanel.translateScreenToJava2D(
new Point(mouseX, mouseY));
//get chart entity
ChartEntity ce = chartPanel.getEntityForPoint((int)p.getX(), (int)p.getY());
//ce is null if you didn't click on a data point
if(ce != null){
String toolTip = ce.getToolTipText();
String [] toolTipCode;
//split the tool tip by delimiter :
//works only if your description doesn't contain a :
toolTipCode = toolTip.split(":");
//do something with toolTipCode[0]
}
}
-----------end-----------------------
This works nicely for what I need.
-----------start---------------------
public void chartMouseClicked(ChartMouseEvent event)
{
int mouseX = event.getTrigger().getX();
int mouseY = event.getTrigger().getY();
Point2D p = chartPanel.translateScreenToJava2D(
new Point(mouseX, mouseY));
//get chart entity
ChartEntity ce = chartPanel.getEntityForPoint((int)p.getX(), (int)p.getY());
//ce is null if you didn't click on a data point
if(ce != null){
String toolTip = ce.getToolTipText();
String [] toolTipCode;
//split the tool tip by delimiter :
//works only if your description doesn't contain a :
toolTipCode = toolTip.split(":");
//do something with toolTipCode[0]
}
}
-----------end-----------------------