Howdy, I noticed that bug 746512 ChartRenderingInfo incorrect after chart resized has been closed. I eagerly downloaded 0.9.9 and tried it out, but I'm still seeing the same problem.
Is there a recommended way to determine the category from a mouse click (ie should I be calling a translatePoint(p) style method?).
Cheers
Andrew
Bug [ 746512 ] closed but not fixed?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Here is the code from the mouseClicked(...) method in the ChartPanel:
Notice how the x and y values are transformed before they are used to determine the entity at that location on the chart. That's important, because sometimes the chart is drawn at a larger size than the panel, then scaled down to fit, OR the chart is drawn at a smaller size than the panel and scaled up to fit.
Code: Select all
public void mouseClicked(MouseEvent event) {
Insets insets = getInsets();
int x = (int) ((event.getX() - insets.left) / scaleX);
int y = (int) ((event.getY() - insets.top) / scaleY);
// old 'handle click' code...
chart.handleClick(x, y, this.info);
// new entity code...
if (this.chartMouseListeners.isEmpty()) {
return;
}
ChartEntity entity = this.info.getEntityCollection().getEntity(x, y);
ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);
Iterator iterator = chartMouseListeners.iterator();
while (iterator.hasNext()) {
ChartMouseListener listener = (ChartMouseListener) iterator.next();
listener.chartMouseClicked(chartEvent);
}
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Thanks for that, I also discovered your translateScreenToJava2D(p) that does just what you mentioned (I couldn't do it as you demonstrated since the scaleX/Y and insets members are private). So now when I override the display I do the following...
Which works like a charm. Thanks for your help.
(c:
Cheers
Andrew
Code: Select all
public displayPopupMenu(int x, int y)
{
Point2D p2d = translateScreenToJava2D(new Point(x, y));
doStuffWithThePoint(p2d);
// now display the menu...
...
}
(c:
Cheers
Andrew
I'm really glad Andrew mentioned that, because it's been bothering me too that ChartPanel's scale{X,Y} and insets are private, without getxxx() methods.
When I started experimenting with Entities in 0.9.8, I made my own version of the ChartPanel class, identical to the "real thing" except with getters added for those members. Obviously that's not a sustainable approach as time and jFeeChart march forward.
Does translateScreenToJava2D(p) really do all that is required?
And on another topic which in my mind is quite closely related, is there any way we can "freeze" the dimensions of the actual plot area so that it won't change as the ValueLabels change in size with autoscaling?
It's a real problem in customized multiple plots, where the horizontal axes _should_ all match up.
Irv
When I started experimenting with Entities in 0.9.8, I made my own version of the ChartPanel class, identical to the "real thing" except with getters added for those members. Obviously that's not a sustainable approach as time and jFeeChart march forward.
Does translateScreenToJava2D(p) really do all that is required?
And on another topic which in my mind is quite closely related, is there any way we can "freeze" the dimensions of the actual plot area so that it won't change as the ValueLabels change in size with autoscaling?
It's a real problem in customized multiple plots, where the horizontal axes _should_ all match up.
Irv
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Hi Irv,
The translateScreenToJava2D(...) method covers all the requirements I can think of, but let me know what you are trying to do and I'll look at it.
The "dynamic" nature of the plot area is a difficult problem to solve, because JFreeChart has been designed that way around. You could try experimenting with the setFixedDimension(...) method in the Axis class...it is used with combined charts to align the axes, the problem is to determine the appropriate dimension.
The translateScreenToJava2D(...) method covers all the requirements I can think of, but let me know what you are trying to do and I'll look at it.
The "dynamic" nature of the plot area is a difficult problem to solve, because JFreeChart has been designed that way around. You could try experimenting with the setFixedDimension(...) method in the Axis class...it is used with combined charts to align the axes, the problem is to determine the appropriate dimension.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


[quote="pietschy"]Thanks for that, I also discovered your translateScreenToJava2D(p) that does just what you mentioned (I couldn't do it as you demonstrated since the scaleX/Y and insets members are private). So now when I override the display I do the following...
[code]
public displayPopupMenu(int x, int y)
{
Point2D p2d = translateScreenToJava2D(new Point(x, y));
doStuffWithThePoint(p2d);
// now display the menu...
...
}
[/code]
Which works like a charm. Thanks for your help.
(c:
Cheers
Andrew[/quote]
[code]
public displayPopupMenu(int x, int y)
{
Point2D p2d = translateScreenToJava2D(new Point(x, y));
doStuffWithThePoint(p2d);
// now display the menu...
...
}
[/code]
Which works like a charm. Thanks for your help.
(c:
Cheers
Andrew[/quote]