现在,此代码从3列数据库中检索数据,并在柱形图(hAxis
)中显示为一行,这意味着: -
清楚示例如下表..我只想从数据库中检索存储在3列中的百分比..标准将手动标记。
________________________
|CRITERIA |PERCENTAGE |
|-----------------------|
|CRITERIA 1 | 64.1 |
|-----------------------|
|CRITERIA 2 | 11.1 |
|-----------------------|
|CRITERIA 3 | 21.1 |
|-----------------------|
非常感谢..
已编辑:getdata.php:
$table = array();
$table['cols'] = array
(
array('label' => 'Criteria', 'type' => 'string'),
array('label' => 'Criteria 1', 'type' => 'number'),
array('label' => 'Criteria 2', 'type' => 'number'),
array('label' => 'Criteria 3', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($sql_query))
{
$temp = array();
$temp[] = array('v' =>"");
$temp[] = array('v' => (float)$r['resultsd']);
$temp[] = array('v' => (float)$r['resultwe']);
$temp[] = array('v' => (float)$r['resulttre']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
这是google可视化代码,名为getdata.php。:
google.load("visualization", "1", {packages:["corechart"]});
function drawVisualization()
{
var jsonData=null;
var json = $.ajax
({
url:"getdata.php?id=<?php echo $_GET['id'];?>",
dataType: "json",
async: false,
success: (
function(data)
{
jsonData = data;
var data = new google.visualization.DataTable(jsonData);
var options =
{
title: 'SAM Histogram Results',
hAxis: {title: " CRITERIA TYPE", titleTextStyle: {italic: false,bold: true}},
vAxis: {title: "PERCENTAGE (%)", titleTextStyle: {italic: false, bold: true}},
titleTextStyle: {color: 'black', bold:'true'},
}
var chart = new google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,options);
})
}).responseText;
}
google.setOnLoadCallback(drawVisualization);