Jsoup data as graph
in
Programming Questions
•
7 months ago
Hello, I'm having some trouble with implementing Jsoup in my graph.
I've been trying to read the data from www.zonox.nl/test.php and to read the numbers and put them in a graph.
So far Jsoup read the data but only saves it when I press a button. And I've made my graph as that it reads data from multiple lines instead of next to each other, how the data is saved now.
My Jsoup code is as followed:
Copy code
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.*;
- import org.jsoup.select.*;
- Document doc = null;
- PrintWriter output;
- BufferedReader reader;
- String line;
- void setup(){
- }
- void draw()
- {
- output = createWriter("waarden.txt");
- try
- {
- doc = Jsoup.connect("http://www.zonox.nl/test.php").get();
- }
- catch (IOException e)
- {
- println(e);
- }
- Elements values = doc.select("body");
- // println(values);
- for (Element value : values)
- {
- output.println (value.text());
- }
- output.flush();
- output.close();
- String lines[] = loadStrings("waarden.txt");
- for (int i = 0 ; i < lines.length; i++) {
- println(lines[i]);
- }
- }
- void keyPressed(){
- output.flush();
- output.close();
- println("Done !");
- exit();
- }
Copy code
- PFont z;
- final static byte numVars = 26;
- final static float[] vars = new float[numVars];
- final static byte marginX = 25, marginY = 50;
- final static color bg = 255;
- final static String fileName = "data/waarden.txt";
- void setup() {
- size(1400, 600);
- frameRate(1);
- z = loadFont( "Andalus-48.vlw" );
- stroke(-1);
- reloadData();
- }
- void draw() {
- if (frameCount % 1 == 0) reloadData();
- textFont(z,12);
- textAlign(CENTER);
- fill(0);
- float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
- z = vars[0];
- a = vars[1];
- b = vars[2];
- c = vars[3];
- d = vars[4];
- e = vars[5];
- f = vars[6];
- g = vars[7];
- h = vars[8];
- i = vars[9];
- j = vars[10];
- k = vars[11];
- l = vars[12];
- m = vars[13];
- n = vars[14];
- o = vars[15];
- p = vars[16];
- q = vars[17];
- r = vars[18];
- s = vars[19];
- t = vars[20];
- u = vars[21];
- v = vars[22];
- w = vars[23];
- x = vars[24];
- y = vars[25];
- background(bg);
- ellipseMode(CENTER);
- noFill();
- stroke(110,225,110);
- strokeWeight(3);
- ellipse(25, 550 - a, a/2, a/2);
- ellipse(75, 550 - b, b/2, b/2);
- ellipse(125, 550 - c, c/2, c/2);
- ellipse(175, 550 - d, d/2, d/2);
- ellipse(225, 550 - e, e/2, e/2);
- ellipse(275, 550 - f, f/2, f/2);
- ellipse(325, 550 - g, g/2, g/2);
- ellipse(375, 550 - h, h/2, h/2);
- ellipse(425, 550 - i, i/2, i/2);
- ellipse(475, 550 - j, j/2, j/2);
- ellipse(525, 550 - k, k/2, k/2);
- ellipse(575, 550 - l, l/2, l/2);
- ellipse(625, 550 - m, m/2, m/2);
- ellipse(675, 550 - n, n/2, n/2);
- ellipse(725, 550 - o, o/2, o/2);
- ellipse(775, 550 - p, p/2, p/2);
- ellipse(825, 550 - q, q/2, q/2);
- ellipse(875, 550 - r, r/2, r/2);
- ellipse(925, 550 - s, s/2, s/2);
- ellipse(975, 550 - t, t/2, t/2);
- ellipse(1025, 550 - u, u/2, u/2);
- ellipse(1075, 550 - v, v/2, v/2);
- ellipse(1125, 550 - w, w/2, w/2);
- ellipse(1175, 550 - x, x/2, x/2);
- ellipse(1225, 550 - y, y/2, y/2);
- ellipse(1275, 550 - z, z/2, z/2);
- //waarden
- fill (0);
- text ( ""+vars[1]+"" , 25,575);
- text ( ""+vars[2]+"" , 75,575);
- text ( ""+vars[3]+"" ,125,575);
- text ( ""+vars[4]+"" ,175,575);
- text ( ""+vars[5]+"" ,225,575);
- text ( ""+vars[6]+"" ,275,575);
- text ( ""+vars[7]+"" ,325,575);
- text ( ""+vars[8]+"" ,375,575);
- text ( ""+vars[9]+"" ,425,575);
- text ( ""+vars[10]+"" ,475,575);
- text ( ""+vars[11]+"" ,525,575);
- text ( ""+vars[12]+"" ,575,575);
- text ( ""+vars[13]+"" ,625,575);
- text ( ""+vars[14]+"" ,675,575);
- text ( ""+vars[15]+"" ,725,575);
- text ( ""+vars[16]+"" ,775,575);
- text ( ""+vars[17]+"" ,825,575);
- text ( ""+vars[18]+"" ,875,575);
- text ( ""+vars[24]+"" ,925,575);
- text ( ""+vars[20]+"" ,975,575);
- text ( ""+vars[21]+"" ,1025,575);
- text ( ""+vars[22]+"" ,1075,575);
- text ( ""+vars[23]+"" ,1125,575);
- text ( ""+vars[19]+"" ,1175,575);
- text ( ""+vars[25]+"" ,1225,575);
- text ( ""+vars[0]+"" ,1275,575);
- //stocklijn
- stroke(110,110,255);
- noFill();
- strokeWeight(3);
- beginShape();
- vertex(25, 550 - a);
- vertex(75, 550 - b);
- vertex(125, 550 - c);
- vertex(175, 550 - d);
- vertex(225, 550 - e);
- vertex(275, 550 - f);
- vertex(325, 550 - g);
- vertex(375, 550 - h);
- vertex(425, 550 - i);
- vertex(475, 550 - j);
- vertex(525, 550 - k);
- vertex(575, 550 - l);
- vertex(625, 550 - m);
- vertex(675, 550 - n);
- vertex(725, 550 - o);
- vertex(775, 550 - p);
- vertex(825, 550 - q);
- vertex(875, 550 - r);
- vertex(925, 550 - s);
- vertex(975, 550 - t);
- vertex(1025, 550 - u);
- vertex(1075, 550 - v);
- vertex(1125, 550 - w);
- vertex(1175, 550 - x);
- vertex(1225, 550 - y);
- vertex(1275, 550 - z);
- endShape();
- //lijnen
- stroke(150);
- strokeWeight(1);
- line(25, 550 - a, 25, 560);
- line(75, 550 - b, 75, 560);
- line(125, 550 - c, 125, 560);
- line(175, 550 - d, 175, 560);
- line(225, 550 - e, 225, 560);
- line(275, 550 - f, 275, 560);
- line(325, 550 - g, 325, 560);
- line(375, 550 - h, 375, 560);
- line(425, 550 - i, 425, 560);
- line(475, 550 - j, 475, 560);
- line(525, 550 - k, 525, 560);
- line(575, 550 - l, 575, 560);
- line(625, 550 - m, 625, 560);
- line(675, 550 - n, 675, 560);
- line(725, 550 - o, 725, 560);
- line(775, 550 - p, 775, 560);
- line(825, 550 - q, 825, 560);
- line(875, 550 - r, 875, 560);
- line(925, 550 - s, 925, 560);
- line(975, 550 - t, 975, 560);
- line(1025, 550 - u, 1025, 560);
- line(1075, 550 - v, 1075, 560);
- line(1125, 550 - w, 1125, 560);
- line(1175, 550 - x, 1175, 560);
- line(1225, 550 - y, 1225, 560);
- line(1275, 550 - z, 1275, 560);
- //namen
- text ( "Aegon" , 25,590);
- text ( "Ahold" , 75,590);
- text ( "KLM" ,125,590);
- text ( "Akzo" ,175,590);
- text ( "Aperam" ,225,590);
- text ( "Arcelor" ,275,590);
- text ( "ASML" ,325,590);
- text ( "Boskalis" ,375,590);
- text ( "Corio" ,425,590);
- text ( "DMB" ,475,590);
- text ( "WeHa" ,525,590);
- text ( "Fugro" ,575,590);
- text ( "Heiniken" ,625,590);
- text ( "ING" ,675,590);
- text ( "KPN" ,725,590);
- text ( "Philips" ,775,590);
- text ( "Randstad" ,825,590);
- text ( "Reed" ,875,590);
- text ( "RDS " ,925,590);
- text ( "SBM" ,975,590);
- text ( "TNT" ,1025,590);
- text ( "Unibail" ,1075,590);
- text ( "Unilever" ,1125,590);
- text ( "DSM" ,1175,590);
- text ( "Wolters" ,1225,590);
- text ( "AEX" ,1275,590);
- }
- void reloadData() {
- String[] data = loadStrings(fileName);
- for ( int i=0; i!=numVars; vars[i] = float(data[i++]) );
- }
1