【问题标题】:Getting a simple JpGraph working with dynamic data获得一个使用动态数据的简单 JpGraph
【发布时间】:2012-12-20 21:56:54
【问题描述】:

我正在努力让一个简单的示例工作,一旦我看到一个工作示例我应该没问题但无法达到这一点,这是我的代码:

foreach($users as $user => $tbl_user_id)
{
    $query = "SELECT * FROM my_table WHERE name = '$user'". $sel_query_tech . "" ;

    $result = mysql_query($query);
    $query_num_rows = mysql_num_rows($result);
    $tc = mysql_num_rows($query);           

    $user_hours_query = "SELECT * FROM tbl_activity WHERE activity_user_id = '$tbl_user_id' AND activity_task_id = '10' ". $sel_query . "" ;
    $result1 = mysql_query($user_hours_query);
    $hours_worked = 0;

            while ($row1 = mysql_fetch_array($result1))
                {
                $hours_worked += $row1['activity_hrs_done'];
                }

    echo '<tr><td>'.$user.'</td>';
    echo '<td>'.$tbl_user_id.'</td>';
    echo '<td>'. $tc_num_rows.'</td>';
    echo '<td>'. number_format($hours_worked,2).'</td>';
    $rt = number_format($query_num_rows / $hours_worked ,2);
    echo '<td>'. $rt.'</td></tr>';  
    $data[]=number_format($hours_worked,2);
    $p1->SetLegends[]=$user;
    }

// Some data
//$data = array(40,21,17,27,23);

// Create the Pie Graph. 
$graph = new PieGraph(400,200,'auto');
$graph->SetShadow();

// Set A title for the plot
$graph->title->Set("3D Pie Client side image map");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Create
$p1 = new PiePlot3D($data);
//$p1->SetLegends(array("Jan (%d)","Feb","Mar","Apr","May","Jun","Jul"));
$targ=array("pie3d_csimex1.php?v=1","pie3d_csimex1.php?v=2","pie3d_csimex1.php?v=3",
            "pie3d_csimex1.php?v=4","pie3d_csimex1.php?v=5","pie3d_csimex1.php?v=6");
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
$p1->SetCSIMTargets($targ,$alts);

// Use absolute labels
$p1->SetLabelType(1);
$p1->value->SetFormat("%d kr");

// Move the pie slightly to the left
$p1->SetCenter(0.4,0.5);

$graph->Add($p1);


// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();

我知道 $p1->SetLegends 是错误的,因为我 print_r 和 $data 都输出,$data 返回值但不是 $p1 但我真的有点迷失了,可以做一些指导。

如果我只使用设置值,例如 $data = 数组(40,21,17,27,23); $p1->SetLegends(array("Jan (%d)","Feb","Mar","Apr","May","Jun","Jul"));

然后它工作正常,所以它与我如何传递信息有关,有什么想法吗?

【问题讨论】:

    标签: php arrays jpgraph


    【解决方案1】:

    请将此代码写入您的代码中。希望对你有帮助

       //$p1->SetLegends[]=$user;
        $userarr[] = $user;
    

    然后

    $p1 = new PiePlot3D($data);
    //$p1->SetLegends(array("Jan (%d)","Feb","Mar","Apr","May","Jun","Jul"));
    
    $p1->SetLegends($userarr);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      相关资源
      最近更新 更多