Results 1 to 4 of 4
  1. #1
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default array lists in jsp and google api

    hey,
    i got an array list and the values of the array list i want to use in my jsp page which has google api in it

    here is the code
    Java Code:
    <%
            ArrayList arrName =(ArrayList)session.getAttribute("arrlist");
            out.print(arrName);
            out.print("<img src=https://chart.googleapis.com/chart?cht=bvg&chd=t:"+arrName+"&chs=500x200&chl=hello|World  />");
            
    %>
    this should print out a bar chart for me because of the google api.
    but the bar chart i want needs to contain the values retrieved from my array list but what i did doesn't work.

    if you want too see what the bar chart should look like type this in your browser: https://chart.googleapis.com/chart?c...hello|my|world

    any help will be greatly appreciated

    thank you

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

    You can't just print the arrName Arraylist like that. You have to build the https string dynamically. Since arrName contains the labels, you need to loop through it and construct the https string properly. For example:

    Java Code:
            ArrayList<String> arrName = new ArrayList<String>();
            arrName.add("red");
            arrName.add("green");
            arrName.add("blue");
            String sLabels = "";
            for (int i=0; i < arrName.size(); i++) {
            	sLabels = sLabels + arrName.get(i);
            	if (i != (arrName.size()-1))
            		sLabels += "|";
            }
            System.out.println("https://chart.googleapis.com/chart?cht=bvg&chd=t:20,10,30&chs=500x200&chl=" + sLabels);
    Notice how the sLabels variable is populated by looping through the arrName ArrayList and getting its values.

    You should do the same thing with the values. Look at the https string above and you'll notice "20,10,30". You should replace that with a variable (e.g. sValues). You'll also need another ArrayList (e.g. arrValues) to contain your values for the chart.

    Once you do that, your chart will be dynamic and the way you want.

  3. #3
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default

    thanks that is really helpful and fully functional/dynamical

    thanks again :)

  4. #4
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

Similar Threads

  1. Array Lists help!!
    By lilika in forum New To Java
    Replies: 12
    Last Post: 01-04-2011, 02:05 PM
  2. Array Lists and Club class
    By amekjian in forum New To Java
    Replies: 13
    Last Post: 11-03-2010, 12:42 AM
  3. Help with arrays and array lists
    By ambernicole88 in forum New To Java
    Replies: 3
    Last Post: 12-04-2009, 09:47 PM
  4. null point exception in array lists
    By c_walker in forum New To Java
    Replies: 3
    Last Post: 10-17-2009, 05:38 AM
  5. please i need the code of comparing these two array lists.
    By raj reddy in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 04-18-2008, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •