I can't clear annotations from a chart taken from MySQL data

Share RGraph:   Share or Like RGraph on Facebook!

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Javier on 5th June 2013
Hello everybody. Salutes from Spain.

My php file is shown below (you can find it here: handyq.textblock.org/?seccion=graficacontrolavisos )

Look to see what is missing, if you are so polite... Personally i think that the problem is due to retrieving datas from mysql (dynamic graph)...

¡¡Thanks!!

Javier


//PHP FILE

***************************************************************
<?php
/**
* Mod GRAFICA de control de avisos
*
* PHP version 5
*
* @category Mod
* @package Handy-q
* @author JJuan <javier@textblock.org>
* @license www.gnu.org/copyleft/gpl.html GNU General Public License
* @link www.textblock.org
*/
    
     $result = mysql_query("SELECT mes, percent FROM controlavisos ORDER BY id ASC");
if ($result) {
    
         $labels = array();
         $data = array();
    
     while ($row = mysql_fetch_assoc($result)) {
             $labels[] = $row["mes"];
             $data[] = $row["percent"];
     }

         // Now you can aggregate all the data into one string
         $data_string = "[" . join(", ", $data) . "]";
         $labels_string = "['" . join("', '", $labels) . "']";
} else {
         print('MySQL query failed with error: ' . mysql_error());
}
?>
<html>
<head>


<a href="www.rgraph.net/\"><img src="www.rgraph.net/images/logo.png\"><br /><strong>Coded by rgraph.net</strong></a><br /><br /><br />

     <!-- Don't forget to update these paths -->

     <script src="libraries/RGraph.common.core.js" ></script>
     <script src="libraries/RGraph.line.js" ></script>
     <script src="libraries/RGraph.common.dynamic.js"></script>
     <script src="libraries/RGraph.common.context.js" ></script>
     <script src="libraries/RGraph.common.tooltips.js"></script>
     <script src="libraries/RGraph.common.annotate.js" ></script>
      <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
<script type="text/javascript" src="apis.google.com/js/plusone.js\"></script>


</head>
<body>
    
     <canvas id="cvs" width="900" height="300">[No canvas support]</canvas>
 

 
     <script>
         chart = new RGraph.Line('cvs', <?php print($data_string) ?>);
         chart.Set('chart.title', 'Porcentaje de avisos por mes');
         chart.Set('chart.title.yaxis', 'Nº de avisos');
         chart.Set('chart.annotatable', true);
         chart.Set('chart.events.click', myFunc3);
         chart.Set('chart.events.mousemove', function (e, shape) {e.target.style.cursor = 'pointer';});
         chart.Set('chart.contextmenu', [
                                 ['Show palette', RGraph.Showpalette],
                                 ['Clear', function () {RGraph.Clear(Line.canvas); Line.Draw();}]
                                ]);
         chart.Set('chart.background.grid.autofit', true);
        
         chart.Set('chart.background.barcolor1', '#f2f2f2');
         chart.Set('chart.background.barcolor2', '#f2f2f2');
         chart.Set('chart.background.grid.color', 'rgba(238,238,238,1)');
         chart.Set('chart.background.grid.autofit.numhlines', 10);
         chart.Set('chart.colors', ['yellow']);
         chart.Set('chart.shadow', true);
         chart.Set('chart.linewidth', 3);
         chart.Set('chart.curvy', 1);
         chart.Set('chart.curvy.factor', 0.25);
         chart.Set('chart.filled', false);
         chart.Set('chart.gutter.left', 35);
         chart.Set('chart.gutter.right', 5);
         chart.Set('chart.gutter.bottom', 100);
         chart.Set('chart.text.angle', 45);
         chart.Set('chart.hmargin', 10);
         chart.Set('chart.tickmarks', 'endcircle');
         chart.Set('chart.tooltips', <?php print($labels_string) ?>);
         chart.Set('chart.labels', <?php print($labels_string) ?>);
         chart.Set('chart.tooltips.effect', 'contract');
            chart.Draw();
           
             /**
         * This is the function that is called when the Pie chart is clicked on
         */
         function myFunc3 (e, shape)
         {
             // If you have multiple charts on your canvas the .__object__ is a reference to
             // the last one that you created
             var obj = e.target.__object__;
    
             var dataset = shape['dataset'];
             var index = shape['index_adjusted'];
             var value = typeof(index) == 'number' ? obj.data[dataset][index] : obj.data[dataset];
    
             alert('Value: ' + value);
         }
           
     </script>

<br /><br /><br />
<a href="../phpMyEdit-5.7.1/controlavisos.php">Editar</a>

</body>
</html>

***********************************************************
Posted by RGraph support on 6th June 2013
Hi there,


You appear to be missing the call to the ClearAnnotations function in your context menu:

chart.Set('chart.contextmenu', [
                                 ['Show palette', RGraph.Showpalette],
                                 ['Clear', function ()
                                           {
                                            RGraph.Clear(chart.canvas);
                                            RGraph.ClearAnnotations(chart.canvas)
                                            chart.Draw();
                                           }
                                 ]
                                ]);


Richard, RGraph Support
Posted by Enter your name... on 6th June 2013
Thanks very much for your answer.

Kind Regards.

:)

Javier

Add a reply




« Back to message list