chenboling / achartengine

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

LineGraph problem/bug #385

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

i think i found a little bug. I'm trying to create a line graph. that is 
realized in the LineGraph class. Within it's constructor LineGraph(Context 
context) i customize my graph. Now the problem is that i create an array of 
random numbers.

        Random r_1 = new Random();
        double[] xAxis_1 = new double[30];
        double[] yAxis_1 = new double[30];
        double[] xAxis_2 = new double[30];
        double[] yAxis_2 = new double[30];
        double rangeMax = 100;
        double rangeMin = 0;

        for(int i=0; i<xAxis_1.length; i++) {
            xAxis_1[i] = rangeMin + (rangeMax - rangeMin) * r_1.nextDouble();
            xAxis_1[i] = Math.round(xAxis_1[i]*100.0)/100.0;
            yAxis_1[i] = rangeMin + (rangeMax - rangeMin) * r_1.nextDouble();
            yAxis_1[i] = Math.round(yAxis_1[i]*100.0)/100.0;
            xAxis_2[i] = rangeMin + (rangeMax - rangeMin) * r_1.nextDouble();
            xAxis_2[i] = Math.round(xAxis_2[i]*100.0)/100.0;
            yAxis_2[i] = rangeMin + (rangeMax - rangeMin) * r_1.nextDouble();
            yAxis_2[i] = Math.round(yAxis_2[i]*100.0)/100.0;
        }

When i add this array into a TimeSeries there is still no error. The error 
shows itself when an Intent or GraphicalView is created. At this moment i get 
an IndexOutOfBoundsException. The error looks like:

01-15 07:47:40.980: E/AndroidRuntime(3310): FATAL EXCEPTION: main
01-15 07:47:40.980: E/AndroidRuntime(3310): Process: 
de.festo.ysr.mvcesima.controllers, PID: 3310
01-15 07:47:40.980: E/AndroidRuntime(3310): 
java.lang.IndexOutOfBoundsException: Invalid index 30, size is 30
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
java.util.ArrayList.get(ArrayList.java:308)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.util.IndexXYMap.getYByIndex(IndexXYMap.java:86)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.model.XYSeries.getY(XYSeries.java:203)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.chart.XYChart.drawChartValuesText(XYChart.java:590)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.chart.XYChart.drawSeries(XYChart.java:534)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.chart.XYChart.draw(XYChart.java:311)
01-15 07:47:40.980: E/AndroidRuntime(3310):     at 
org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)

And the biggest mystery here is that when i define the array without random 
numbers the error is gone.

        xAxis_1 = new double[30];
        yAxis_1 = new double[30];
        xAxis_2 = new double[30];
        yAxis_2 = new double[30];

        for(int i=0; i<xAxis_1.length; i++) {
            xAxis_1[i] = i;
            yAxis_1[i] = i;
            xAxis_2[i] = i;
            yAxis_2[i] = i;
        }

The fact that the error is gone after declaring the array without random 
numbers menas that the problem has something to do with the Random class or the 
array it self.

Original issue reported on code.google.com by yasarism...@googlemail.com on 15 Jan 2014 at 1:06

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I found something that prevents the error. When i do this 
setDisplayChartValues(false) then there are no problems anymore. strange. 
Couldn't find something in the source code.

Original comment by yasarism...@googlemail.com on 15 Jan 2014 at 1:21

GoogleCodeExporter commented 9 years ago
I came across this little bug too.

Original comment by Europa2...@gmail.com on 7 Mar 2014 at 1:40

GoogleCodeExporter commented 9 years ago

Original comment by dandrome...@gmail.com on 16 Sep 2014 at 7:20