shuaiwangVM / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

XYChart method fails to return correct clickable area for series #288

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I believe there is a bug in XYChart.java getSeriesAndPointForScreenCoordinate() 
function. The line 

for (int seriesIndex = clickableAreas.size() - 1; seriesIndex >= 0; 
seriesIndex--) {

is intended to iterate through indexes of clickable areas, but then the code 
tries to retrieve the corresponding clickableArea for series using seriesIndex 
as a key:

if (clickableAreas.get(seriesIndex) != null) { ...

which is incorrect, since clickableAreas is a Map and not a List, so the get() 
method requires a key and not index. As a result, the code either retrieves 
incorrect clickable areas, or just null when there are more than one series.

Proposed solution:

--- svn/trunk/achartengine/src/org/achartengine/chart/XYChart.java  2013-03-22 
11:09:51.748946041 +0100
+++ svn/trunk/achartengine/src/org/achartengine/chart/XYChart.java  2013-03-22 
11:11:23.872944251 +0100
@@ -866,7 +866,7 @@

   public SeriesSelection getSeriesAndPointForScreenCoordinate(final Point screenPoint) {
     if (clickableAreas != null)
-      for (int seriesIndex = clickableAreas.size() - 1; seriesIndex >= 0; 
seriesIndex--) {
+      for (Integer seriesIndex: clickableAreas.keySet()) {
         // series 0 is drawn first. Then series 1 is drawn on top, and series 2
         // on top of that.
         // we want to know what the user clicked on, so traverse them in the

BR,

Vadim

Original issue reported on code.google.com by vvma...@gmail.com on 22 Mar 2013 at 10:25

GoogleCodeExporter commented 9 years ago
Map<Integer, List<ClickableArea>> clickableAreas; the key is the series index.

Original comment by dandrome...@gmail.com on 3 Apr 2013 at 3:59

GoogleCodeExporter commented 9 years ago
This is a replacement: seriesSelection=new SeriesSelection(seriesIndex, 
startIndex+pointIndex, area.getX(), area.getY());

Original comment by 474238...@qq.com on 13 Aug 2013 at 7:57