2012-03-07 100 views
0

我有一個chartview,它基本上是一個圖像視圖。我需要爲此添加十字準線。當用戶在任何地方觸摸圖表時,我需要獲取XY座標,將它們映射到我的數據集,最後使用映射的值更新文本視圖。所以當用戶移動十字線時,我將動態更新帶有相應值的文本視圖。如何捕獲移動十字線AFreeCharts的十字準線座標?

我添加了一個onTouchListener的圖像,並得到了XY座標,但堅持將XY座標映射到我的數據集(我在數據集內有多個TimeSeries)。另外我很困惑,如果我可以使用plot.getDomainCroshairValue()& plot.geRangeCroshairValue()來獲取數據集的值。

任何人都可以告訴我如何在使用AFreeChart庫時完成此操作?

Need to know when to use plot.handleClick(x, y, plotrendingInfo) ? 

感謝 Akhash

回答

1

從的Javadoc:AFreeChart.handleClick()

/** 
* Handles a 'click' on the chart. AFreeChart is not a UI component, so some 
* other object (for example, {@link DemoView}) needs to capture the click 
* event and pass it onto the AFreeChart object. If you are not using 
* AFreeChart in a client application, then this method is not required. 
* 
* @param x 
*   x-coordinate of the click (in Java2D space). 
* @param y 
*   y-coordinate of the click (in Java2D space). 
* @param info 
*   contains chart dimension and entity information (
*   <code>null</code> not permitted). 
*/ 

public void handleClick(int x, int y, ChartRenderingInfo info) { 

    // pass the click on to the plot... 
    // rely on the plot to post a plot change event and redraw the chart... 
    this.plot.handleClick(x, y, info.getPlotInfo()); 

} 

視圖的的onTouchEvent()應該被實現,當觸摸事件發生應翻譯提供MotionEvent對象成爲一個Afreechart的handleClick(),然後代表Plot.handleClick()

XYPlot.handleClick()已經有c反演機制將X,Y座標轉換爲數據集X,Y值。