paragp / achartengine

AChartEngine is a charting library for Android applications. It currently supports the following chart types: line chart area chart scatter chart time chart bar chart pie chart bubble chart doughnut chart range (high-low) bar chart dial chart / gauge combined (any combination of line, cubic line, scatter, bar, range bar, bubble) chart cubic line chart All the above supported chart types can contain multiple series, can be displayed with the X axis horizontally (default) or vertically and support many other custom features. The charts can be built as a view that can be added to a view group or as an intent, such as it can be used to start an activity. The model and the graphing code is well optimized such as it can handle and display huge number of values. AChartEngine is currently at the 1.0.0 release. New chart types will be added in the following releases. Please keep sending your feedback such as we can continually improve this library. Find us on Facebook, too: http://www.facebook.com/achartengine Read a short introduction to AChartEngine here: http://www.javaadvent.com/2012/12/achartengine-charting-library-for.html Another good tutorial can be read here: http://jaxenter.com/effort-free-graphs-on-android-with-achartengine-46199.html
0 stars 1 forks source link

When running an asynctask and adding negative values to series.add, it throws an IllegalArgumentException #314

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've attached a sample Android studios project to simplify this description. 

I created a new XYSeriesRenderer, and on a background thread I'm adding values 
to the series and showing a preview. 
like so: series.add(x[i], values[i]);, where -50 <= x <= 50, and -2500 <= 
values <= 2500. (values = x^2) and interval of 0.1.

I occasionally get this thrown:
 java.lang.IllegalArgumentException: -49.9 > -61.39999999999945
Full logcat attached.

Note: there are a couple things that make this more complicated. This is a 
timing issue. Reducing the values to -5 <= x <= 5, and -25 <= values <= 25, 
will not run into this issue. Also, debugging this also avoids the issue.

Second thing is, if you add a positive value first, you won't run into this 
issue. It's only if you run negative values first that don't get processed fast 
enough.

Please provide a source code snippet that we can use to replicate the issue.
See attached. I've added the full project, the MainActivity file and layout. 
Use whatever is easiest.

What version of the product binary library are you using?
1.2.0

Other comments:
When running the application, you have two buttons.
1. Runs the negative values. Occasionally this works, and if it does then force 
close the application (or swipe away in the recent apps list). It should 
eventually crash.

2. Runs positive values only from 0 < x < 50, and 0 < values < 2500.
Run this once, and then you can run 1 as many times as you like. 

Original issue reported on code.google.com by ydin...@gmail.com on 7 Jun 2013 at 11:30

Attachments:

GoogleCodeExporter commented 9 years ago
I've narrowed it down to line 301 of XYSeries.java

// this would be simply: end = mXY.higherKey(end) but NavigableMap is
      // available since API 9
      // so we have to do this hack in order to support older versions
      SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
      if (!tailMap.isEmpty()) {
        Iterator<Double> tailIterator = tailMap.keySet().iterator();
        Double next = tailIterator.next();
        if (tailIterator.hasNext()) {
          stop = tailIterator.next();
        } else {
          stop += next;
        }
      }

When it does 'stop += next', if stop is negative, it can make it smaller than 
start. 

I have no clue what any of this code does, but I'm hoping that it's possible to 
change the 'else' condition to 'else if stop > 0'.

It works for my test case. A better solution would be to find out why it 
sometimes goes in there, and sometimes it doesn't. 

Original comment by ydin...@gmail.com on 13 Jun 2013 at 11:24

GoogleCodeExporter commented 9 years ago

Original comment by dandrome...@gmail.com on 31 Oct 2013 at 8:16