SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic graph in php

    I want to create a dynamic graph for the date and total columns on the webpage
    http://www.weblunar.com/forex2/track_record.php
    this data in the table is pulled from the database.

    here is the graph code(graph.php)
    PHP Code:
    <?php
    # PHPlot Example: Bar chart, 3 data sets, shaded
    require_once 'phplot.php';

    $data = array(
      array(
    'Jan'40), array('Feb'30), array('Mar'20),
      array(
    'Apr'10), array('May',  3), array('Jun',  7),
      array(
    'Jul'10), array('Aug'15), array('Sep'20),
      array(
    'Oct'18), array('Nov'16), array('Dec'14),
    );

    $plot = new PHPlot(600300);
    $plot->SetImageBorderType('plain');

    $plot->SetPlotType('bars');
    $plot->SetDataType('text-data');
    $plot->SetDataValues($data);

    # Main plot title:
    $plot->SetTitle('Track record');

    # Make a legend for the 3 data sets plotted:
    //$plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration'));

    # Turn off X tick labels and ticks because they don't apply here:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');

    $plot->DrawGraph();

    ?>

    and the code the table page[PHP]
    <?php
    require("inc/conn.php");
    $page 7;
    //get this page's content from the database
    $sql "SELECT * FROM tblpages WHERE pageID = " .$page;
    if (
    $result mysql_query($sql)) {
        
    $row mysql_fetch_array($result);
        
    $pageHeading $row['pageHeading'];
        
    $pageContent $row['pageContent'];
    }

        
    //build and issue query
    $sql "SELECT * FROM trackrecord ORDER BY date";
    $result = @mysql_query($sql) or die(mysql_error());
    $num=mysql_numrows($result);
    mysql_close();



    require_once(
    'header.php'); ?>
    <style type="text/css">
    <!--
    @import url("css/table.css");
    -->
    </style>


    <div id="content_alert">
          <div class="post1">
                <h1><?php echo $pageHeading?></h1>
                <table id="mytable" cellspacing="0" summary="">
    <caption>Track record </caption>
    <tr>
      <th scope="col" abbr="date">date</th>
      <th scope="col" abbr="currency pair">currency pair</th>
      <th scope="col" abbr="recommended lot size">entry price</th>
      <th scope="col" abbr="suggested entry">profit 1</th>
      <th scope="col" abbr="suggested stop">profit 2</th>
      <th scope="col" abbr="time of call">profit 3</th>
      <th scope="col" abbr="valid till">daily net</th>
      <th scope="col" abbr="target p1">total to date</th>
      
      </tr>
      
     <?
    $i
    =0;
    while (
    $i $num) {

    $field1 =mysql_result($result,$i,"date");
    $field2 =mysql_result($result,$i,"pair");
    $field3 =mysql_result($result,$i,"entry_price");
    $field4 =mysql_result($result,$i,"profit_1");
    $field5=mysql_result($result,$i,"profit_2");
    $field6 =mysql_result($result,$i,"profit_3");
    $field7 =mysql_result($result,$i,"daily_net");
    $field8 =mysql_result($result,$i,"total_to_date");
    ?>


    <tr>
      <td><? echo $field1?></td>
      <td><? echo $field2?></td>
      <td><? echo $field3?></td>
      <td><? echo $field4?></td>
      <td><? echo $field5?></td>
      <td><? echo $field6?></td>
      <td><? echo $field7?></td>
      <td><? echo $field8?></td>
      
     </tr>
     
    <?
    $i
    ++;
    }

    echo 
    "</table>";  
    ?>
    <div class="">&nbsp;</div>

    <div style="float: left; width: 400px;">
            <div><img src="includes/graph.php"></div>
        </div>
                
      </div>
     </div>
     
    <?php require_once('footer.php'); ?>

    thank you
    [/PHP]

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by parkerproject View Post
    I want to create a dynamic graph for the date and total columns on the webpage
    http://www.weblunar.com/forex2/track_record.php
    this data in the table is pulled from the database.

    here is the graph code(graph.php)
    PHP Code:
    <?php
    # PHPlot Example: Bar chart, 3 data sets, shaded
    require_once 'phplot.php';

    $data = array(
      array(
    'Jan'40), array('Feb'30), array('Mar'20),
      array(
    'Apr'10), array('May',  3), array('Jun',  7),
      array(
    'Jul'10), array('Aug'15), array('Sep'20),
      array(
    'Oct'18), array('Nov'16), array('Dec'14),
    );

    $plot = new PHPlot(600300);
    $plot->SetImageBorderType('plain');

    $plot->SetPlotType('bars');
    $plot->SetDataType('text-data');
    $plot->SetDataValues($data);

    # Main plot title:
    $plot->SetTitle('Track record');

    # Make a legend for the 3 data sets plotted:
    //$plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration'));

    # Turn off X tick labels and ticks because they don't apply here:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');

    $plot->DrawGraph();

    ?>

    and the code the table page[PHP]
    <?php
    require("inc/conn.php");
    $page 7;
    //get this page's content from the database
    $sql "SELECT * FROM tblpages WHERE pageID = " .$page;
    if (
    $result mysql_query($sql)) {
        
    $row mysql_fetch_array($result);
        
    $pageHeading $row['pageHeading'];
        
    $pageContent $row['pageContent'];
    }

        
    //build and issue query
    $sql "SELECT * FROM trackrecord ORDER BY date";
    $result = @mysql_query($sql) or die(mysql_error());
    $num=mysql_numrows($result);
    mysql_close();



    require_once(
    'header.php'); ?>
    <style type="text/css">
    <!--
    @import url("css/table.css");
    -->
    </style>


    <div id="content_alert">
          <div class="post1">
                <h1><?php echo $pageHeading?></h1>
                <table id="mytable" cellspacing="0" summary="">
    <caption>Track record </caption>
    <tr>
      <th scope="col" abbr="date">date</th>
      <th scope="col" abbr="currency pair">currency pair</th>
      <th scope="col" abbr="recommended lot size">entry price</th>
      <th scope="col" abbr="suggested entry">profit 1</th>
      <th scope="col" abbr="suggested stop">profit 2</th>
      <th scope="col" abbr="time of call">profit 3</th>
      <th scope="col" abbr="valid till">daily net</th>
      <th scope="col" abbr="target p1">total to date</th>
      
      </tr>
      
     <?
    $i
    =0;
    while (
    $i $num) {

    $field1 =mysql_result($result,$i,"date");
    $field2 =mysql_result($result,$i,"pair");
    $field3 =mysql_result($result,$i,"entry_price");
    $field4 =mysql_result($result,$i,"profit_1");
    $field5=mysql_result($result,$i,"profit_2");
    $field6 =mysql_result($result,$i,"profit_3");
    $field7 =mysql_result($result,$i,"daily_net");
    $field8 =mysql_result($result,$i,"total_to_date");
    ?>


    <tr>
      <td><? echo $field1?></td>
      <td><? echo $field2?></td>
      <td><? echo $field3?></td>
      <td><? echo $field4?></td>
      <td><? echo $field5?></td>
      <td><? echo $field6?></td>
      <td><? echo $field7?></td>
      <td><? echo $field8?></td>
      
     </tr>
     
    <?
    $i
    ++;
    }

    echo 
    "</table>";  
    ?>
    <div class="">&nbsp;</div>

    <div style="float: left; width: 400px;">
            <div><img src="includes/graph.php"></div>
        </div>
                
      </div>
     </div>
     
    <?php require_once('footer.php'); ?>

    thank you
    [/PHP]

    What's your question?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can i make the x-axis and y-axis dynamic?

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by parkerproject View Post
    how can i make the x-axis and y-axis dynamic?
    You're going to have to be more specific than that, what do you mean by dynamic?

    The more detailed of a question you ask, the better answer you will get in return.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i want to put the information into arrays then output it on the both x and y axis.
    i mean the information on the date column and also total to date column
    you can view the table here
    http://www.weblunar.com/forex2/track_record.php

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not take the easy approach, and use a library such as jpgraph for your graphing
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  7. #7
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by parkerproject View Post
    i want to put the information into arrays then output it on the both x and y axis.
    i mean the information on the date column and also total to date column
    you can view the table here
    http://www.weblunar.com/forex2/track_record.php
    Isn't that what this is doing?

    PHP Code:
    $data = array(
      array(
    'Jan'40), array('Feb'30), array('Mar'20),
      array(
    'Apr'10), array('May',  3), array('Jun',  7),
      array(
    'Jul'10), array('Aug'15), array('Sep'20),
      array(
    'Oct'18), array('Nov'16), array('Dec'14),
    ); 
    I'm probably misunderstanding your question.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  8. #8
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes you are right,all i want now is do a loop within the array,don't know if it is possible

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $data = array();
    while(
    $row $someloop){
        
    $data[$row['column']] = $row['data'];

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by parkerproject View Post
    yes you are right,all i want now is do a loop within the array,don't know if it is possible
    Oh, I understand now, it would have been helpful if you had been really specific on what you were trying to do.

    The answer is pretty simple:

    PHP Code:
    ...
    $data = array();

    while (
    $i $num) {
    ...
    $field7 =mysql_result($result,$i,"daily_net");
    $field8 =mysql_result($result,$i,"total_to_date");

    $data[] = array($field1$field8);

    ?>
    ... 
    And then comment out $data in your other file.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  11. #11
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot brad

  12. #12
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have tried the code,but is not retrieving and displaying the graph

    PHP Code:
    <?php
    # PHPlot Example: Bar chart, 3 data sets, shaded
    require_once 'phplot.php';
    require_once(
    '../inc/conn.php'); 


        
    //build and issue query
    $sql "SELECT * FROM trackrecord ORDER BY date";
    $result = @mysql_query($sql) or die(mysql_error());
    $num=mysql_numrows($result);
    mysql_close();


    $data = array();
    $i=0;
    while (
    $i $num) {
    $field1 =mysql_result($result,$i,"date");
    $field8 =mysql_result($result,$i,"total_to_date");

    $data[] = array($field1$field8);
    }

    /*$data = array(
      array('Jan', 40), array('Feb', 30), array('Mar', 20),
      array('Apr', 10), array('May',  3), array('Jun',  7),
      array('Jul', 10), array('Aug', 15), array('Sep', 20),
      array('Oct', 18), array('Nov', 16), array('Dec', 14),
    );*/

  13. #13
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i adjusted it to
    PHP Code:
    $data = array();
    $i=0;
    while (
    $i $num) {
    $field1 =mysql_result($result,$i,"date");
    $field8 =mysql_result($result,$i,"total_to_date");
    $i++;

    $data[] = array($field1$field8);

    and it worked

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to be more efficient with your querying.

    PHP Code:
    $sql "SELECT date, total_to_date FROM trackrecord ORDER BY date"
    $result mysql_query($sql) or die(mysql_error()); 
    $data = array(); 
    while(
    $row mysql_fetch_assoc($result)) {
        
    $data[] = $row;

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #15
    SitePoint Addict mason.sklut's Avatar
    Join Date
    Oct 2006
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For time's sake, take a look at Google's Graph API.

    http://code.google.com/apis/chart/

    It will save you time, and make your app more efficient!

    - Mason


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
  •