MartynLearnsPHP Posted December 26, 2014 Share Posted December 26, 2014 (edited) 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 December 26, 2014 by MartynLearnsPHP Quote Link to comment https://forums.phpfreaks.com/topic/293372-selecting-timestamp-date-for-use-in-google-annotation-chart/ Share on other sites More sharing options...
MartynLearnsPHP Posted December 26, 2014 Author Share Posted December 26, 2014 (edited) 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 December 26, 2014 by MartynLearnsPHP Quote Link to comment https://forums.phpfreaks.com/topic/293372-selecting-timestamp-date-for-use-in-google-annotation-chart/#findComment-1500743 Share on other sites More sharing options...
MartynLearnsPHP Posted December 29, 2014 Author Share Posted December 29, 2014 Sorry to bump - but can anyone offer any suggestions here? Quote Link to comment https://forums.phpfreaks.com/topic/293372-selecting-timestamp-date-for-use-in-google-annotation-chart/#findComment-1500988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.