1

iam trying to show multiple Graphs in one diagram. The datasource is a MySQL database which is connected via PHP. My Problem: I cant figure out how to add the data to the RGraph Script. I managed to show one graph via PHP, bt i cant add a seconde one. This is how i succsessfully get the Data (After connecting to the Database ofc.): Important!: (At least i guess it is) i have two different cases, in one Case the return Data is a single Number (eg: "2") in my seconde case it is an array of 52 different numbers.

$1 = mysql_query("SELECT * FROM Table WHERE spalte1 ='XX' AND spalte2 ='XX' ORDER BY Datum DESC Limit 1");
    if ($1) {

        $labels = array();
        $data   = array();

        while ($row = mysql_fetch_assoc($1)) {
            $labels[] = $row["datum"];
            $2[] = $row["max"];
        }
        // Now you can aggregate all the data into one string
        $2_string = "[" . join(", ", $2) . "]";
        $labels_string = "['" . join("', '", $labels) . "']";
    } 
    else 
    {
        print('MySQL query failed with error: ' . mysql_error());
    }       

This is how i draw the Graph:

<canvas id="cvs" width="1200" height="250">[Browser not supported]</canvas>
            <script>
            //window.onload = function ()
            //{
            new RGraph.Line({
                    id:'cvs',
                    data:[<?php print($2_string) ?>],
                    options: {
                        colors:['#B71A1A'],
                        backgroundGrid: true,
                        //xaxisLabels: [<?php print($labels_string) ?>],
                        //xaxisLabelsAngle: 25,
                        xaxis: true,
                        yaxis: true,
                        yaxisScale: true,
                        yaxisScaleUnitsPost:'%',
                        yaxisScaleMax: 100,
                        title: 'XX',
                        textAccessible: true,
                        key: ['XX'],
                        keyPosition: 'margin',
                        keyPositionX: 25,

                    }
                }).draw();

But how can i add a seconde graph into this diagram? All the Demos say something like:

data = [[1,2,3],[4,5,6]]

So i tryed different versions (just one example):

data = [[<?php print($1_string) ?>],[<?php print($2_string) ?>]]

Hopefully someone has an Idea ... :)

Thx for every try :)

  • This could take some answering - so please submit a support request at https://www.rgraph.net/support.html#support-form No need to post a massive message - I just need your email address so that I can reply – Richard Jun 19 '20 at 08:38

1 Answers1

1

Here is what I sent Simon via email

<?php
    $1_data = 5;
    $2_data = array(2,3,8 4,6,8,6,9,8,7,5,8);

    // Make JavaScript arrays out of the above number and PHP array
    // also making an array of two numbers out of the single number
    $1_string = '[' . join(',', array($1_data, $1_data) . ']';
    $2_string = '[' . join(',', $2_data) . ']';
?>

<canvas id="cvs" width="1200" height="250">[Browser not supported]</canvas>

<script>
    new RGraph.Line({
        id:'cvs',
        data:[
            <?php print($1_string) ?>,
            <?php print($2_string) ?>
        ],
        options: {
        }
    }).draw();
</script>
Richard
  • 4,809
  • 3
  • 27
  • 46