2016-05-28 5 views
0

ラベル。変数に応じて列を表示します(このようなもの):Googleのチャート列は、私は次のコードしている

$rows = array(); 
$table = array(); 
$table['cols'] = array(
    array('label' => 'Date', 'type' => 'string'), 
if ($current == "true") {** 
    array('label' => 'Charging Current', 'type' => 'number'), 
} 
if ($voltage == "true") { 
    array('label' => 'Battery Voltage', 'type' => 'number'),  
} 
if ($power == "true") { 
    array('label' => 'Charging Power', 'type' => 'number'), 
} 
if ($rotation == "true") { 
    array('label' => 'Rotation', 'type' => 'number'), 
} 
); 

$rows = array(); 
while($r = mysql_fetch_assoc($sth)) { 
    $temp = array(); 
    // the following line will be used to slice the chart 
    $temp[] = array('v' => (string) $r['TimeStamp']); 

    // Values of each slice 
    if ($current == "true") { 
     $temp[] = array('v' => (int) $r['ChargingCurrent']); 
     $rows[] = array('c' => $temp); 
    } 
    if ($voltage == "true") { 
     $temp[] = array('v' => (int) $r['BatteryVoltage']); 
     $rows[] = array('c' => $temp); 
    } 
    if ($power == "true") { 
     $temp[] = array('v' => (int) $r['ChargingPower']); 
     $rows[] = array('c' => $temp); 
    } 
    if ($rotation == "true") { 
     $temp[] = array('v' => (int) $r['Rotation']); 
     $rows[] = array('c' => $temp); 
    } 
} 

私は何をしようとしていますか?私を助けてください。

答えて

0

$tables['col']アレイに簡単に項目を追加できます。あなたのケースでは

$table['cols'][] = 'something';

、あなたのコードは、希望は、このようなものになります。これを行うのアレイに何かを追加するには

$rows = array(); 
$table = array(); 
$table['cols'] = array(
    array('label' => 'Date', 'type' => 'string') 
); 

if ($current == "true") { 
    $table['cols'][] = array('label' => 'Charging Current', 'type' => 'number'); 
} 
if ($voltage == "true") { 
    $table['cols'][] = array('label' => 'Battery Voltage', 'type' => 'number'); 
} 
if ($power == "true") { 
    $table['cols'][] = array('label' => 'Charging Power', 'type' => 'number'); 
} 
if ($rotation == "true") { 
    $table['cols'][] = array('label' => 'Rotation', 'type' => 'number'); 
} 
); 
+0

をハハ、私はちょうどあなたがまったく同じことをやっている実現します行の下にあなたのコード。私はあなたが列について全く同じことをすることができると確信しています。おそらく私はあなたが意味することを誤解しています...? – BizzyBob

+0

ありがとうございました。それがまさに私が必要としていたものです。 私はいくつかのプロジェクトを接続するためにphpだけを使用します。私はその問題の解決方法を理解できませんでした。 – Witek

関連する問題