Bar Graph Generator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Darby

    #1

    Bar Graph Generator

    Hi all!

    I wonder if anyone can help with a problem I am having with a sctipt I have
    written. It uses the information stored in a cookie to generate a bar graph
    of sales for a range of cooking pans. I have managed to read the cookie
    information and draw the graph. The cookie is split and the values places
    into two arrays. The cookie however, stores information on the preferences
    for a text resizing facility in addition to the pan sales information. This
    produces some unrequired information to be written to the graph. The
    contents of the cookie is as follows:

    sales=pan1=23,p an3=153,pan4=21 ,pan9=5; style=default

    I only wish to use the information up to the semicolon, that is everything
    other than style=default. How can I whilst splitting the cookie into the
    two arrays, discard the unwanted information? Any help would be greatfully
    received. Many thanks in advance. The script appears below:

    <script language="javas cript" type="text/javascript">

    var array1 = new Array();
    var array2 = new Array();
    var what = unescape(docume nt.cookie);
    array1[0] = '' + what.substr(0,w hat.indexOf("=" )) + '';
    what = what.substr(wha t.indexOf("=")+ 1);
    var pair = what.split(",") ;
    var j = 1;
    var k = 0;
    for (var i=0; i<pair.length; i++) {
    var item = pair[i].split("=");
    array1[j++] = '' + item[0] + '';
    array2[k++] = item[1];
    }
    what = unescape(docume nt.cookie);
    what += "<br><br> array1 = " + array1.join("," );
    what += "<br><br> array2 = " + array2.join("," );
    document.write( what);

    document.write( "<h2><u>"+array 1[0]+"<\/u><\/h2><table>")
    for (j=1; j<array1.length ; j++) {
    document.write( "<tr><td><p><br ><\/p><h3>"+array1[j]+"<\/h3><\/td><\/tr>")
    document.write( "<tr><td><i mg src='images/lilBlue.gif' height='20'
    width='"+(array 2[j-1]*3)

    +"'>")
    document.write( "&nbsp;&nbsp;"+ array2[j-1]+"<\/td><\/tr>")
    }
    document.write( "<\/table>")

    </script>


  • McKirahan

    #2
    Re: Bar Graph Generator

    "Steve Darby" <ramesses_the_g reat@ntlworld.c om> wrote in message
    news:xx8Id.73$7 S3.6@newsfe3-gui.ntli.net...[color=blue]
    > Hi all!
    >
    > I wonder if anyone can help with a problem I am having with a sctipt I[/color]
    have[color=blue]
    > written. It uses the information stored in a cookie to generate a bar[/color]
    graph[color=blue]
    > of sales for a range of cooking pans. I have managed to read the cookie
    > information and draw the graph. The cookie is split and the values places
    > into two arrays. The cookie however, stores information on the[/color]
    preferences[color=blue]
    > for a text resizing facility in addition to the pan sales information.[/color]
    This[color=blue]
    > produces some unrequired information to be written to the graph. The
    > contents of the cookie is as follows:
    >
    > sales=pan1=23,p an3=153,pan4=21 ,pan9=5; style=default
    >
    > I only wish to use the information up to the semicolon, that is everything
    > other than style=default. How can I whilst splitting the cookie into the
    > two arrays, discard the unwanted information? Any help would be[/color]
    greatfully[color=blue]
    > received. Many thanks in advance. The script appears below:
    >
    > <script language="javas cript" type="text/javascript">
    >
    > var array1 = new Array();
    > var array2 = new Array();
    > var what = unescape(docume nt.cookie);
    > array1[0] = '' + what.substr(0,w hat.indexOf("=" )) + '';
    > what = what.substr(wha t.indexOf("=")+ 1);
    > var pair = what.split(",") ;
    > var j = 1;
    > var k = 0;
    > for (var i=0; i<pair.length; i++) {
    > var item = pair[i].split("=");
    > array1[j++] = '' + item[0] + '';
    > array2[k++] = item[1];
    > }
    > what = unescape(docume nt.cookie);
    > what += "<br><br> array1 = " + array1.join("," );
    > what += "<br><br> array2 = " + array2.join("," );
    > document.write( what);
    >
    > document.write( "<h2><u>"+array 1[0]+"<\/u><\/h2><table>")
    > for (j=1; j<array1.length ; j++) {
    > document.write( "<tr><td><p><br ><\/p><h3>"+array1[j]+"<\/h3><\/td><\/tr>")
    > document.write( "<tr><td><i mg src='images/lilBlue.gif' height='20'
    > width='"+(array 2[j-1]*3)
    >
    > +"'>")
    > document.write( "&nbsp;&nbsp;"+ array2[j-1]+"<\/td><\/tr>")
    > }
    > document.write( "<\/table>")
    >
    > </script>[/color]

    Change the assignment of "what" to include the last line below:

    var what = unescape(docume nt.cookie);
    what = what.substr(wha t.indexOf("=")+ 1);
    what = what.substr(0,w hat.indexOf(";" ));


    Comment

    • Steve Darby

      #3
      Re: Bar Graph Generator

      Hi there,

      Thanks for your reply. I managed to chieve the result I wanted by altering
      the line:

      var what = unescape(docume nt.cookie);

      to

      var what = unescape(docume nt.cookie.split ("; "")[0]);

      which splits the two cookie and selects only the first to be acted on by the
      following code.

      Many thanks again for your initial help. It is very much appreciated.

      Regards,

      Steve



      "McKirahan" <News@McKirahan .com> wrote in message
      news:ivSdnf5IL-wugmzcRVn-3Q@comcast.com. ..[color=blue]
      > "Steve Darby" <ramesses_the_g reat@ntlworld.c om> wrote in message
      > news:xx8Id.73$7 S3.6@newsfe3-gui.ntli.net...[color=green]
      >> Hi all!
      >>
      >> I wonder if anyone can help with a problem I am having with a sctipt I[/color]
      > have[color=green]
      >> written. It uses the information stored in a cookie to generate a bar[/color]
      > graph[color=green]
      >> of sales for a range of cooking pans. I have managed to read the cookie
      >> information and draw the graph. The cookie is split and the values
      >> places
      >> into two arrays. The cookie however, stores information on the[/color]
      > preferences[color=green]
      >> for a text resizing facility in addition to the pan sales information.[/color]
      > This[color=green]
      >> produces some unrequired information to be written to the graph. The
      >> contents of the cookie is as follows:
      >>
      >> sales=pan1=23,p an3=153,pan4=21 ,pan9=5; style=default
      >>
      >> I only wish to use the information up to the semicolon, that is
      >> everything
      >> other than style=default. How can I whilst splitting the cookie into the
      >> two arrays, discard the unwanted information? Any help would be[/color]
      > greatfully[color=green]
      >> received. Many thanks in advance. The script appears below:
      >>
      >> <script language="javas cript" type="text/javascript">
      >>
      >> var array1 = new Array();
      >> var array2 = new Array();
      >> var what = unescape(docume nt.cookie);
      >> array1[0] = '' + what.substr(0,w hat.indexOf("=" )) + '';
      >> what = what.substr(wha t.indexOf("=")+ 1);
      >> var pair = what.split(",") ;
      >> var j = 1;
      >> var k = 0;
      >> for (var i=0; i<pair.length; i++) {
      >> var item = pair[i].split("=");
      >> array1[j++] = '' + item[0] + '';
      >> array2[k++] = item[1];
      >> }
      >> what = unescape(docume nt.cookie);
      >> what += "<br><br> array1 = " + array1.join("," );
      >> what += "<br><br> array2 = " + array2.join("," );
      >> document.write( what);
      >>
      >> document.write( "<h2><u>"+array 1[0]+"<\/u><\/h2><table>")
      >> for (j=1; j<array1.length ; j++) {
      >> document.write( "<tr><td><p><br ><\/p><h3>"+array1[j]+"<\/h3><\/td><\/tr>")
      >> document.write( "<tr><td><i mg src='images/lilBlue.gif' height='20'
      >> width='"+(array 2[j-1]*3)
      >>
      >> +"'>")
      >> document.write( "&nbsp;&nbsp;"+ array2[j-1]+"<\/td><\/tr>")
      >> }
      >> document.write( "<\/table>")
      >>
      >> </script>[/color]
      >
      > Change the assignment of "what" to include the last line below:
      >
      > var what = unescape(docume nt.cookie);
      > what = what.substr(wha t.indexOf("=")+ 1);
      > what = what.substr(0,w hat.indexOf(";" ));
      >
      >[/color]


      Comment

      Working...