CLICK IN CHART- CAPTURE DATA

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 CHART- CAPTURE DATA

Post by anibanm » Wed May 30, 2007 10:06 am

Hello, I’m telling you my problem!

I need capture one event (click in one point of chart) to tick this point in a Jtable. But domain are dates….
double xx = plot.getDomainCrosshairValue(); How could I capture the dates?

Here I put a piece of my code:

public void chartProgress(ChartProgressEvent event) {
if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) { return;}
if (this.chartPanel != null) {
JFreeChart c = this.chartPanel.getChart();
if (c != null) {
XYPlot plot = (XYPlot) c.getPlot();
XYDataset dataset = plot.getDataset();
Comparable seriesKey = dataset.getSeriesKey(0);
double xx = plot.getDomainCrosshairValue();
//¿Capture row? Domain are dates


/*Rectangle r =getCellRect(row, column, true);
this.pnlScroll.getViewport().scrollRectToVisible(r); */
}
}
}
Could somebody help me?

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 May 30, 2007 1:38 pm

If your x-values are dates, you should interpret the crosshair value ('xx' in your code) as "milliseconds since 1-Jan-1970".
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 » Thu May 31, 2007 8:40 am

Thank you very much!
OK, but now I need index of every date in dataset.
I've a problem, I can't use series.getIndex(RegularPeriod) because my XYdataset was obtain like JDBCXYDataset.
How I could do it?

public void chartProgress(ChartProgressEvent event) {
if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) { return;}
if (this.chartPanel != null) {
JFreeChart c = this.chartPanel.getChart();
if (c != null) {
XYPlot plot = (XYPlot) c.getPlot();
XYDataset dataset = plot.getDataset();
Comparable seriesKey = dataset.getSeriesKey(0);
double xx = plot.getDomainCrosshairValue();

long millis = (long) xx;
Date d= new Date(millis);
Minute m=new Minute(d);


/*Rectangle r =getCellRect(row, column, true);
this.pnlScroll.getViewport().scrollRectToVisible(r); */
}
}
}

Locked