hi,
Newbie in webdev (and in english) & javascript.
I have realized a aeachart witch use data passed by a JSON and AJAXcall. it's work fine, Now, i would use date format but ....
--------------------------------------------------------
I copy/paste code that works :
areachart :
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url:"plant_graph_height.php",
datatype:"json",
async:false
}).responseText;
var data = new google.visualization.DataTable(JSON.parse(jsonData));
var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
ac.draw(data, {
title : 'Evolution - Hauteur de la plante',
width: 750,
height: 300,
vAxis: {title: "Hauteur (cm)"},
hAxis: {title: "Date"},
colors: ['limegreen'],
legend : {position: 'in'},
pointSize : 5
});
}
</script>
</head>
<body>
<div id="visualization"></div>
</body>
</html>
and plant_graph_height.php :
$table = array();
$table['cols'] = array(
array('label' => 'date', 'type' => 'string'),
array('label' => 'Hauteur', 'type' => 'number')
);
$rows = array();
while ($donnees = $result->fetch())
{
$temp = array();
$temp[] = array('v' => $donnees["height_date"]);
$temp[] = array('v' => $donnees["height"]);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsontable = json_encode($table);
echo $jsontable;
json return by plant_graph_height.php is :
{"cols":[{"label":"date","type":"string"},{"label":"Hauteur","type":"number"}],"rows":[{"c":[{"v":"2012-09-05"},{"v":"15"}]},{"c":[{"v":"2012-09-07"},{"v":"18"}]},{"c":[{"v":"2012-09-12"},{"v":"25"}]},{"c":[{"v":"2012-09-19"},{"v":"35"}]},{"c":[{"v":"2012-09-30"},{"v":"50"}]},{"c":[{"v":"2012-10-14"},{"v":"64"}]}]}
--------------------------------------------------------
Now, my problem....
I want format date in a 'short' format. I have try several tests but it's doesn't work.
For exemple, when i change "array('label' => 'date', 'type' => 'string')," by "array('label' => 'date', 'type' => 'date'),", return is an red box whith "b[wa] is not a function" :(
Can you help me for understand this behavior ?