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.

Edited by MartynLearnsPHP
Link to comment
Share on other sites

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>

Edited by MartynLearnsPHP
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.