2014-11-03 92 views
0

我有一个PHP文件,从SQL表中提取数据,然后将其添加到json编码表。然后,我使用Dashboard/Control/Chart Wrapper类将其读入Google图表表格可视化中。然而,当我尝试从php/json代码中将filterColumnlabel设置为我的列标签之一时,我收到错误:“一个或多个参与者未能绘制”和“无效列标签:汽车”。Google Chart Chart包装过滤器标签

请帮助一些,我的json表SEEMS格式正确,我无法确定是什么导致错误。

$rows = array(); 
$flag = true; 
$table = array(); 
$table['cols'] = array(
    array('label' => 'Date', 'type' =>'string'), 
    array('label' => 'Car', 'type' =>'string'), 
    array('label' => 'Total Cost', 'type' =>'number'), 
    array('label' => 'Mileage', 'type' =>'number') 
); 

// $table = array(
//  array('Date', 'Sales'), 
//  array('June 25', 12.25), 
//  array('June 26', 8.00) 
//); 

for ($x = 0; $x < $count; $x++) 
{ 
$temp = array(); 
$temp[] = array('v' => (string) $dateComplete[$x]); 
$temp[] = array('v' => (string) $Car[$x]); 
$temp[] = array('v' => (float) $TotalCost[$x]); 
$temp[] = array('v' => (float) $mpgAverage[$x]); 
$rows[] = array('c' => $temp); 
} 

$table['rows'] = $rows; 

?> 

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta name="Description" content="Basic Gray"> 
<title>Gas Log</title> 
<link rel="stylesheet" href="stylesheets/default.css"> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> 
<script type="text/javascript" src="javascripts/behavior.js"></script> 

<!--Load the AJAX API--> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript"> 

    // Load the Visualization API and the controls package. 
    // Packages for all the other charts you need will be loaded 
    // automatically by the system. 
    google.load('visualization', '1.0', {'packages':['controls']}); 

    // Set a callback to run when the Google Visualization API is loaded. 
    google.setOnLoadCallback(drawDashboard); 

    function drawDashboard() { 
    // Everything is loaded. Assemble your dashboard... 

     var table = <?php echo json_encode($table);?>; 

     var data = new google.visualization.arrayToDataTable([table]); 

     console.log(table); 

     var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div')); 

     // Create a range slider, passing some options 
     var StringSlider = new google.visualization.ControlWrapper({ 
      'controlType': 'StringFilter', 
      'containerId': 'control_div', 
      'options': { 
      'filterColumnLabel': 'Car' 
      } 
     }); 

     // Create a pie chart, passing some options 
     var Chart = new google.visualization.ChartWrapper({ 
      'chartType': 'ColumnChart', 
      'containerId': 'chart_div', 
      'options': { 
      'width': 300, 
      'height': 300, 
      'pieSliceText': 'value', 
      'legend': 'right' 
      } 
     }); 

     // Establish dependencies, declaring that 'filter' drives 'pieChart', 
     // so that the pie chart will only display entries that are let through 
     // given the chosen slider range. 
     dashboard.bind(StringSlider, Chart); 

     // Draw the dashboard. 
     dashboard.draw(data); 
    } 
</script> 

回答

0

如果您提供您的整个代码(特别是4个数组引用dateComplete,租车,TOTALCOST,mpgAverage)我可以帮你,但没有它,我刚刚被猜测。