Dygraph Annotations

99 views
Skip to first unread message

AP

unread,
Dec 4, 2014, 2:40:18 PM12/4/14
to dygraph...@googlegroups.com
Hello,

i would set annoatations and would save the annotations in a MYSQL database.

I load the data although from a MYSQL database. This is running.

Here is a scipt to load the last Annotation from the database, but it would not be displayed in the graph.

Can someone help me?

 <?php  
  $annotation_data  
= mysql_query("SELECT DATE_FORMAT(xval,'%Y-%m-%d %H:%i:%s') AS xval1, xval, series, shortText, text
                        FROM annotations ORDER BY xval DESC LIMIT 1"
) or die(mysql_error());
 
  $r_data1
= mysql_fetch_array($annotation_data);
  $xval11  
= 1417004339;
  $series1  
= $r_data1['series'];
  $shortText1  
= $r_data1['shortText'];
  $text1  
= $r_data1['text'];  
 
?>
var ann = {
            series: $series1,
            xval: $xval11,
            shortText: $shortText1,
            text: $text1
            };
          var anns = graphdiv2.annotations();
          anns.push(ann);
          graphdiv2.setAnnotations(anns);


Dan Vanderkam

unread,
Dec 4, 2014, 2:45:34 PM12/4/14
to dygraph...@googlegroups.com
Check your JS console for errors.

--
You received this message because you are subscribed to the Google Groups "dygraphs-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dygraphs-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AP

unread,
Dec 4, 2014, 3:02:25 PM12/4/14
to dygraph...@googlegroups.com
which console, i send it direct to webserver, no error message.

AP

unread,
Jan 10, 2015, 4:42:14 AM1/10/15
to dygraph...@googlegroups.com
Hello, this Problem was solved.

<?php
  $annotation_data  = mysql_query("SELECT DATE_FORMAT(xval,'%Y/%m/%d %H:%i:%s') AS xval1, xval, series, shortText, text
                        FROM ".$database_anno." ORDER BY xval  ") or die(mysql_error());
 
  while($row = mysql_fetch_array($annotation_data))
  {
  $text = str_replace("\r\n", "<br>", $row['text']);       // eingebaute Umbrüche ausbessern
  $aaa = " " .$aaa. "{series: '".$row[series]."', x: Date.parse('".$row[xval1]."'), shortText: '".$row[shortText]."', text: '" .$text."'}," ;
 
    }
  ?>
  
  graphdiv2.setAnnotations([<?php echo $aaa ?>]);     // Annotations anzeigen
 



Why dos tis not run?

var dat "[{series: 'AKKU [V]', x: Date.parse('2014/07/06 12:58:12'), shortText: 'A', text: 'Akku geladen'}]"
     
   

   
graphdiv2.setAnnotations(dat);    

This runs.

graphdiv2.setAnnotations([{series'AKKU [V]'xDate.parse('2014/07/06 12:58:12'), shortText'A'text'Akku geladen'}]);


Can help me somebody?
Reply all
Reply to author
Forward
0 new messages