Can ChartMouseEvent return the description of a TimeSeries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
JDJ
Posts: 7
Joined: Fri Aug 11, 2006 4:35 pm

Can ChartMouseEvent return the description of a TimeSeries

Post by JDJ » Mon Aug 28, 2006 9:53 pm

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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Aug 29, 2006 3:31 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

JDJ
Posts: 7
Joined: Fri Aug 11, 2006 4:35 pm

Post by JDJ » Tue Aug 29, 2006 10:58 pm

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-----------------------

Locked