Clickable legends?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rannic
Posts: 1
Joined: Fri Mar 24, 2006 9:33 pm

Clickable legends?

Post by rannic » Fri Mar 24, 2006 9:46 pm

Pre-1.0, when you clicked on a legend, a ChartMouseEvent was generated whose Entity was a LegendItemEntity. Of course, now that legends are no different from any other title, these events are no longer thrown. I tried using the LegendTitle's getBounds() and related methods, but they return zeros. Has anyone come up with a good way to handle clicking on legends?

hulagutten
Posts: 3
Joined: Wed Mar 22, 2006 10:52 pm
Contact:

Post by hulagutten » Mon Mar 27, 2006 11:32 pm

I would definitely be interested in this as well...

frejos
Posts: 1
Joined: Wed May 09, 2012 3:06 pm
antibot: No, of course not.

Re: Clickable legends?

Post by frejos » Wed May 09, 2012 3:08 pm

Has anybody found a solution for this by now. I only can get the sizes of the single LegendLabelBlocks, but have by now not found a way to retrieve to position of the legendtitle... :cry:

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Clickable legends?

Post by John Matthews » Thu May 10, 2012 2:09 am

Looks OK to me in 1.0.14:

LegendItemEntity java.awt.geom.Rectangle2D$Double[x=249.0,y=458.515625,w=38.0,h=18.484375]
LegendItemEntity java.awt.geom.Rectangle2D$Double[x=289.0,y=458.515625,w=56.0,h=18.484375]
LegendItemEntity java.awt.geom.Rectangle2D$Double[x=347.0,y=458.515625,w=44.0,h=18.484375]

Code: Select all

chartPanel.addChartMouseListener(new ChartMouseListener() {

    @Override
    public void chartMouseClicked(ChartMouseEvent e) {
        String name = e.getEntity().toString().split(":")[0];
        System.out.println(name + " " + e.getEntity().getArea());
    }

    @Override
    public void chartMouseMoved(ChartMouseEvent e) {}

});

Locked