SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrays and Graphs

    Hi

    I have been trying to create a graph using data taken from my database. The data is from 3 selected rows, each row has 4 columns. Here is the code:-


    $query=mysql_query("SELECT * FROM profilereport WHERE profilereport.profilereportid=$value");

    $_SESSION['rows']=array(); $_SESSION['row']=array();

    while ($row=mysql_fetch_row($query))
    {
    array_push($_SESSION['rows'], $row);
    }

    foreach($_SESSION['rows'] as $row)
    {

    for($x=0; $x<4; $x++) //test echo results to screen
    {

    echo $row[$x];

    }

    }


    The graphing program I am using is JpGraph and trying to implement the following code and graph:-

    Test suite for JpGraph - new_bar1.php

    My question is, how do I take the data from my array and use it to create the graph?

    Any help/suggections would be greatly appreciated

    Thanks, Shane

  2. #2
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While there are many ways to do this, for a simple graph you could use your array values to populate the with of a background image on a div. For instance to show the graph at the midpont width="50%" would work, etc.

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Is the row index your X-index, or your G-index?

    (IE: Is one row all the entries for one color of bar on the graph, or the entries for "A" on your example page)

  4. #4
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One row is all the entries for one color and then the second row would be the second color and the third row the third color etc.

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    so then
    PHP Code:
    $bargroups = array()
    while(
    $row $result->fetch_row()) {
      
    $bargroups[] = new BarPlot($row);
    }
    $gbplot = new GroupBarPlot($bargroups); 

  6. #6
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great, worked after after some tweaking of the graph code.
    Thankyou


Tags for this Thread

Bookmarks

Posting Permissions

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