CLICK in a categoryplot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anibanm
Posts: 12
Joined: Thu May 17, 2007 4:12 pm

CLICK in a categoryplot

Post by anibanm » Wed Jun 27, 2007 9:04 am

Hello,
I have a LineChart. When I click in a point in chart I'd like to get its category.

I've achieved my aim in a XYPlot with the following code:

Code: Select all

public void chartProgress(ChartProgressEvent event) {
            if (event.getType() != ChartProgressEvent.DRAWING_FINISHED)  {
                return;
            }
             if (this.panel != null) {
                JFreeChart c = this.panel.getChart();                
                if (c != null) {
                    XYPlot plot = (XYPlot) c.getPlot();
                    XYDataset dataset = plot.getDataset();
                    double xx = plot.getDomainCrosshairValue(); 
                    int itemIndex=this.series.indexOf(xx);
                    this.table.changeSelection(itemIndex,0,false,false);
                    
                    }   
                }
            }
double xx = plot.getDomainCrosshairValue();



But I don't know how doig it in a LineChart(CategoryPlot).

I need your help, thank's.

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 » Wed Jun 27, 2007 9:13 am

It depends on whether you mean a click on a data point or a click on any point in the chart. In the former case, the ChartMouseEvent will have a CategoryItemEntity that you can inspect. In the latter case, you'll need to take the mouse coordinates relative to the chart's data area, and then use the CategoryAxis and dataset to try to derive which category contains the click point (I haven't done this myself - it's definitely possible, but not straightforward).
David Gilbert
JFreeChart Project Leader

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

anibanm
Posts: 12
Joined: Thu May 17, 2007 4:12 pm

Post by anibanm » Wed Jun 27, 2007 10:23 am

OK, now it's fine.

Thank's a lot.

Locked