Cláudio
Cláudio

Reputation: 13

How to do a dynamic arraylist in achartengine

I am using achartengine to construct a graph.

To get a static series I do something like this :

List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
y.add(new double[] { 0, 11, 10, 10, 11, 10, 10, 10, 9, 10, 10, 10 });
addXYSeries(dataset, new String[] { "title" }, x, y, 0);

But I would like to do two things:

  1. I will read a .txt file to get the the x and y value, how to put this read values, (that will be string), into the x or y arraylist? As a matter of fact, I will read many lines of a txt file, and I will have to get a list.

    line1 = "0001 0020 0240 0045";
    line2 = "0015 0020 0240 0045";
    line3 = "0030 0022 0240 0045";
    line4 = "0045 0025 0240 0045";

So, in this exemplo my x will be 1 15 30 45 and my y 20 20 22 25

  1. I thing the answer here will something like the above... I would like to get the value from two variables that will have the x and y values, and then go constructing a dynamic arraylist, adding values as they show up.

I have used Double.valueOf(String) and works great. But I still have a problem,

why this works:

 double[] s ;
 List<double[]> y = new ArrayList<double[]>();

y.add(new double[] {1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4});   

and it does not?

s[0]=1;
s[1]=2;
s[2]=3;
s[3]=4;
s[4]=5;
s[5]=6;
s[6]=7;
s[7]=8;
s[8]=7;
s[9]=6;
s[10]=5;
s[11]=4;
y.add(s);   

Isn´t it the same ?

Upvotes: 0

Views: 172

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201497

1) Double.valueOf(String) - This will return a double value given a String - or throw an Exception if the String can't be mapped to a double.
2) I believe you want to create coordinate (or tuple) class and then create a List.

Upvotes: 1

Related Questions