0

这是我的代码:

 <?php    
    //Set content-type header
    header("Content-type: image/png");

    //Include phpMyGraph5.0.php
    include_once('phpMyGraph5.0.php');
    include("koneksi.php");

    //Set config directives
    $cfg['title'] = 'Example graph';
    $cfg['width'] = 500;
    $cfg['height'] = 250;


    //Set data
    $query="select col1, col2 from tab1 where sub_project = 'sometext'";
    $result=mysql_query($query);
    $row = mysql_fetch_assoc($result);
    $data = array(
        $row['col1'] => $row['col2'],
    );

    //Create phpMyGraph instance
    $graph = new phpMyGraph();

    //Parse
    $graph->parseVerticalColumnGraph($data, $cfg);
?>

在我的例子中,数据 incol1是一个文本,而 incol2是一个数字。但是使用该代码,该图仅显示第一行值。同时来自数据库的值不止一个值。

4

1 回答 1

0

像这样在 while 循环中添加获取的结果。

<?php    
    //Set content-type header
    header("Content-type: image/png");

    //Include phpMyGraph5.0.php
    include_once('phpMyGraph5.0.php');
    include("koneksi.php");

    //Set config directives
    $cfg['title'] = 'Example graph';
    $cfg['width'] = 500;
    $cfg['height'] = 250;


    //Set data
    $query="select col1, col2 from tab1 where sub_project = 'sometext'";
    $result=mysql_query($query);
    $data = array();
    while($row = mysql_fetch_assoc($result))
    {
       $data[$row['col1']] = $row['col2'];
    }

    //Create phpMyGraph instance
    $graph = new phpMyGraph();

    //Parse
    $graph->parseVerticalColumnGraph($data, $cfg);
?>

并且$data是多数组,并且拥有来自数据库的所有记录

希望这段代码对你有帮助

于 2013-08-14T08:48:44.573 回答