Jump to content

Selecting Timestamp Date for use in Google Annotation Chart


MartynLearnsPHP

Recommended Posts

Following on from my problem with another Google Chart which jay0316 kindly helped with, I have another issue which I am hoping that someone might be able to help me with.

 

I am trying to put together a site for my wife to manage her diabetes and insulin intake. We want to monitor her blood/sugar glucose over periods of time (but with notes that she includes that can help monitor reasons for outlying results such as illness), so I am trying to include a Google Annotation Chart to do this, drawing on blood/glucose readings stored in a Database.

 

Where I am struggling at the moment is converting timestamps into information that I can include in the chart.

 

What I currently have at the moment (which obviously isn't working) is:

<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script>
      <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotationchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('datetime', 'Date');
        data.addColumn('number', 'Readings');
        data.addColumn('string', 'Notes');
        data.addRows([
		<?php
$annotate=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0");
foreach ($annotate->results() as $annotateresults)
{
$date=date("Y, m, d",strtotime($annotateresults->timestamp)+18000);
$reading=$annotateresults->reading;
if($annotateresults->notes==""){
$notes="undefined";
} else {
$notes=$annotateresults->notes;
}
echo "[new Date(".$date."), ".$reading.", ".$notes."],";
}
?>

]); var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div_annotate')); var options = { displayAnnotations: true }; chart.draw(data, options); } </script>

Any help is very gratefully received.

Sorry. It won't let me edit my original post. For ease of viewing (ie. all as code rather than just half of it), the current code should read as:

<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script>
      <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotationchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('datetime', 'Date');
        data.addColumn('number', 'Readings');
        data.addColumn('string', 'Notes');
        data.addRows([
		<?php
$annotate=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0");
foreach ($annotate->results() as $annotateresults)
{
$date=date("Y, m, d",strtotime($annotateresults->timestamp)+18000);
$reading=$annotateresults->reading;
if($annotateresults->notes==""){
$notes="undefined";
} else {
$notes=$annotateresults->notes;
}
echo "[new Date(".$date."), ".$reading.", ".$notes."],";
}
?>
]); var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div_annotate')); var options = { displayAnnotations: true }; chart.draw(data, options); } </script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.