Reputation: 13
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:
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
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
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