Two or more Scatter charts in one page


« 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 gooddmood on 18th October 2012
hi again ,
i have made two scatter charts in one page but the problem is the first didnt work and the second work . and if i remove the second the first will work .

here is my code what i have done :

   var age = <?php echo $_SESSION['age'];?>;
         var weight = <?php echo $_SESSION['weight'];?>;
         window.onload = function ()
         {
       
             // Create and configure the Scatter chart
             var scatter = new RGraph.Scatter('wfa_b', [
                                                  [age,weight, 'black'],
                                                  [442,weight, '#CE2118'],
                                                  [124.85,2, 'black'],
                                                  [124,2, 'black'],
                                                  [5,111, 'gray'],
                                                  [5,112, 'red'],
                                                  [12,114, 'gray'],
                                                  [0,110, 'black']
                                                 ]);
             scatter.Set('chart.xmax', 24.85);
    scatter.Set('chart.ymax', 16.6);
             scatter.Set('chart.labels', ['06','07','08','09','10','11','1Year','13','14','15','16','17','18','19','20','21','22','23','2Years']);
    
             bubble = new RGraph.Scatter.Bubble(scatter, 0, // Minimum
                                                         250, // Maximum
                                                         25, // Max width
                                                         [50,50,50,50,90,84,86,87] // Bubble data
                                                        );
             bubble.Draw();
         }
         var length = <?php echo $_SESSION['length'];?>;
         window.onload = function ()
         {
       
             // Create and configure the Scatter chart
             var scatter2 = new RGraph.Scatter('lfa_b', [
                                                  [age,length, 'black'],
                                                  [442,length, '#CE2118'],
                                                  [124.85,2, 'black'],
                                                  [124,2, 'black'],
                                                  [5,111, 'gray'],
                                                  [5,112, 'red'],
                                                  [12,114, 'gray'],
                                                  [0,110, 'black']
                                                 ]);
             scatter2.Set('chart.xmax', 24.85);
    scatter2.Set('chart.ymax', 16.6);
             scatter2.Set('chart.labels', ['06','07','08','09','10','11','1Year','13','14','15','16','17','18','19','20','21','22','23','2Years']);
    
             bubble2 = new RGraph.Scatter.Bubble(scatter2, 0, // Minimum
                                                         250, // Maximum
                                                         25, // Max width
                                                         [50,50,50,50,90,84,86,87] // Bubble data
                                                        );
             bubble2.Draw();
         }


whats wrong please ?
i have search for this problem in documentation but didnt find it
hope i get help thx so much
Posted by RGraph Support on 19th October 2012
Hi,

You're defining two window.onload functions - first you're defining on which creates the first chart. Then you're defining another which makes the second hart. The second overwrites the first - hence only the second chart is being drawn.

So create both charts inside one window.onload function:

<script>
     window.onload = function (e)
     {
         // Create both charts here...
     }
</script>

Add a reply

 




« Back to message list
RGraph on social media