changing cvs getting data from mysql database

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 Guy on 14th August 2013
I'm a software novice, I've got a radar chart to work and get the labels from a mysql database but don't know how to change the cvs to get the values. I am using php so the labels come as <?php print($labels_string) ?>

My code to so far looks like this


         $labels = array();
         $data = array();
    
         while ($row = mysql_fetch_assoc($result)) {
             $labels[] = $row["weekly_tasks"];
             $labels2[] = $row["labels"];
             $labels3[] = $row["nametwo"];
             $data[] = $row["percentage"];

         }

         // Now you can aggregate all the data into one string array('label' => 'Percentage', 'type' => 'number')
         $labels_string = "['" . join("', '", $labels) . "']";
         $labels_string2 = "['" . join("', '", $labels2) . "']";
         $labels_string3 = "['" . join("', '", $labels3) . "']";
         $data_string = "[" . join(", ", $data) . "]";
     } else {
         print('MySQL query failed with error: ' . mysql_error());
     }
?>

what am I missing/done wrong?
Posted by RGraph support on 14th August 2013
Hi there,

It depends on what the variable $data_string looks like. You might be able to do this:

radar = new RGraph.Radar('cvs', <?php $data_string ?> );
radar.Draw();

View the source in your browser to see what that ends up looking like. It needs to look something like this:

radar = new RGraph.Radar('cvs', [4,8,6,3,2] );
radar.Draw();




Richard, RGraph Support
Posted by Guy on 14th August 2013
woops it is a rose graph not radar

this works with the labels but not the data


         {
             var rose = new RGraph.Rose
                  ('cvs', [[<?php $data_string1 ?>,<?php $data_string2 ?>,<?php $data_string3 ?>],[12,4,3],[18,6,8],[8,1,8],[4,3,7],[2,1,2],[34,3,37]])
                 .Set('gutter.bottom', 35)
                 .Set('margin', 6)
                 .Set('labels', [[ <?php print($labels_string1) ?>],[ <?php print($labels_string2) ?>],[ <?php print($labels_string3) ?>],[ <?php print($labels_string4) ?>],[ <?php print($labels_string5) ?>],[ <?php print($labels_string6) ?>]])
                 .Set('text.size', 16)
                 .Set('text.size.scale', 8)
                 .Set('labels.axes', 'n')
                 .Draw();
         }

above it i have

         $data_string1= "[" . join(", ", $data1) . "]";
         $data_string2 = "[" . join(", ", $data2) . "]";
         $data_string3 = "[" . join(", ", $data3) . "]";
     } else {

next idea please... ta
Posted by RGraph support on 14th August 2013
Hi there,

Try either viewing source in your browser to see what your variables are being printed as and post a URL to your page. And until you get things working reduce your code to the bare minimum:


var rose = new RGraph.Rose('cvs', [ <?php $data_string1 ?> ])
     .Draw();

You can then build it up step-by-step.




Richard, RGraph Support
Posted by Guy on 14th August 2013
I simplified it and the source shows that no value is being found for <?php $data_string1 ?>

Could it be that one of these needs some code to tell it it is dealing with a number/integer value rather than text?

         $data = array();

OR
             $data1[] = $row["entryOneOne"];

OR
         $data_string1= "[" . join(", ", $data1) . "]";
OR

<?php print($labels_data1) ?>

that's just a guess from a novice!!!!
Posted by RGraph support on 14th August 2013
Hi there,

Try changing your $data_string1 variable to just a text string so that you can get it up and running:

$data_string1 = '[4,8,6,3,5]';

Then you can get your chart up and running. After that - your PHP may need looking at.

PS. Stop reposting your message.




Richard, RGraph Support
Posted by Guy on 14th August 2013
sorry about the reposting but when i refreshed the page your captcha said it hadn't orked so i tried again, i'll ignore the warning from now on.

I have now got it to work with one problem.

This works


                  ('cvs', [[2,4,2],[2,4,8],[2,4,3],[2,4,6],[6,4,7],<?php print($data_string1) ?>,<?php print($data_string2) ?>,<?php print($data_string3) ?>])

but the 3 data-strings aren't stacked because of the missing [] but put them in and the source shows double [ around the value [[5]]

next idea please Richard
Posted by RGraph support on 14th August 2013
Hi there,

You need to compare your source code that has the PHP in it and the output (that you see when you view source in your browser). It might be helpful if you lose any extraneous stuff - so try just one PHP data set:

('cvs', [ <?php print($data_string1) ?> ])

then two:

('cvs', [ <?php print($data_string1) ?> , <?php print($data_string2) ?>])

then three:

('cvs', [ <?php print($data_string1) ?> , <?php print($data_string2) ?> , <?php print($data_string3) ?> ])

All the time viewing source and comparing the output that you server is sending to the browser.

It might also make things a little bit clearer if you format the code like this:




var rose = new RGraph.Rose('cvs', [
                                    <?php print($data_string1) ?> ,
                                    <?php print($data_string2) ?> ,
                                    <?php print($data_string3) ?>
                                   ])





Richard, RGraph Support
Posted by Guy on 14th August 2013
I have done all that it's just the stacking that isn't working.

each data_string only supplies one value

so I need three data_strings to get three values

which does work but they don't display as a stack

if I put [] around three data-strings in the cvs then the code stops working because the source ends up with two lots of [] around the value because <?php print($data_string1) ?> supplies its value inside []
!!!!
Posted by RGraph support on 14th August 2013
Hi there,

Then you may have to just specify:

obj.Set('chart.accumulative', true);




Richard, RGraph Support
Posted by Guy on 14th August 2013
where do i put that, remember i am a virgin around php!!!
Posted by RGraph support on 14th August 2013
Hi there,

No actually - thats a Radar thing and you're using the Rose. Format your data so that it looks like this:

var obj = new RGraph.Rose('cvs', [
                                   [1,2,3],
                                   [4,5,6],
                                   [7,8,9]
                                  ]);

By default, with the Rose chart, that should display stacked. If you need a guide then try this:

www.rgraph.net/demos/rose-stacked.html


Richard, RGraph Support
Posted by Guy on 14th August 2013
i understand that but...

if I put [] around three data-strings in the cvs then the code stops working because the source ends up with two lots of [] around the value because <?php print($data_string1) ?> supplies its value inside []
Posted by RGraph support on 14th August 2013
Hi there,

Then don't put square brackets in. Do it like this:


var obj = new RGraph.Rose('cvs', [
                                    <?php echo $data_string1 ?> ,
                                    <?php echo $data_string2 ?> ,
                                    <?php echo $data_string3 ?>
                                   ]);




Richard, RGraph Support
Posted by Guy on 14th August 2013
I have done that, they give a good result but then they aren't stacked.

can this

         $data_string1 = "['" . join("', '", $data1) . "']";

have three values in it, something like this (but this doesn't work)

         $data_string1 = "['" . join($data1, $data2, $data3) . "']";
Posted by RGraph support on 14th August 2013
Hi there,

What is $data1? A number? If so why are you using it with join()? That's for arrays. eg:

$data1 = array(4,8,6,3,5);
$data2 = array(8,6,4,3,2);
$data3 = array(4,8,6,3,3);

$data_string1 = '[' . join(',', $data1) . ']';
$data_string2 = '[' . join(',', $data2) . ']';
$data_string3 = '[' . join(',', $data3) . ']';

var obj = new RGraph.Rose('cvs', [
                                     <?php echo $data_string1 ?> ,
                                     <?php echo $data_string2 ?> ,
                                     <?php echo $data_string3 ?>
                                    ]);



Richard, RGraph Support

Add a reply




« Back to message list