views:

120

answers:

2

I have a JFreeChart instance that displays process memory status, initialized as follows:

m_data = new TimeSeriesCollection();
TimeSeries vmsize = new TimeSeries("VMSize");
TimeSeries resident = new TimeSeries("Resisdent");
TimeSeries shared = new TimeSeries("Shared memory");
TimeSeries code = new TimeSeries("Code");
TimeSeries data = new TimeSeries("Data");
m_data.addSeries(vmsize);
m_data.addSeries(resident);
m_data.addSeries(shared);
m_data.addSeries(code);
m_data.addSeries(data);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Memory usage", "Time", "Size", m_data, true, true, false);
m_chart = new ChartPanel(chart);

Later I add values to each TimeSeries in the TimeSeriesCollection. I would like to somehow know - when the user clicks on the Chart - either what time associated with that columm, or even better - what is the index of the value.

I looked at the JFreeChart and ChartMouseListener classes, but I could not figure out how to do that (also the documentation of JFreeChart is annoyingly scarce, I guess they are trying to get people to buy their developer's guide).

+2  A: 

hmm should work, if you replace the last two lines by something like this:

ChartPanel panel=new ChartPanel(ChartFactory.createTimeSeriesChart("Memory usage", "Time", "Size", m_data, true, true, false)));
panel.addChartMouseListener(new ChartMouseListener(){
    void chartMouseClicked(ChartMouseEvent e){
        [...do something on click...]
    }
    void chartMouseMoved(ChartMouseEvent e){
        [...do something on move...]
    }
});
return panel;
smeg4brains
Well, I already looked at ChartMouseLIstener, the information in the event is pretty useless. the question is not how to add a listener - but rather how to obtain the relevant data from the event.
Omry
you can use ChartEvent.getEntity() to get the shape (bar,line) under the mouse http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/entity/ChartEntity.html
smeg4brains
+1, works like a champ!
trashgod
Yes, I seen the getShape() API call already. what I am after is the data this shapre represents. the shape itself depends on the zoom and viewport of the chart.
Omry
A: 

Omry, did you get an answer to this?

Anu
No... I never did.
Omry