Flot (Array 3 values)

60 views
Skip to first unread message

Olalla IP

unread,
Apr 11, 2016, 10:15:58 PM4/11/16
to Flot graphs
I have a table on a database with 3 rows: Date Start, Date End, Medication

Mi PHP code:   

    $sql = "SELECT * FROM medications ORDER BY DateStart";
    $stmt = $PDO -> query($sql);
    $result=$stmt -> fetchAll(PDO::FETCH_ASSOC);
       
    foreach ($result as $row){
    $dateini= $row['DateStart'];
    $datend= $row['DateEnd'];   
    $medic= $row['Medication'];
       
    $data1 = array(strtotime($dateini)*1000,$medic);
    $data2 = array(strtotime($datend)*1000,$medic);
       
    $data3[] = array($data1,$data2);
   
    }

If I do:

    echo json_encode($data3);

I get the array:
    [[[1456531200000,"12"],[1456704000000,"12"]],[[1456531200000,"16"],[1456704000000,"16"]],[[1456617600000,"13"],[1456790400000,"13"]],[[1456704000000,"14"],[1457049600000,"14"]]]


    <script>
    var data3 = <?php echo json_encode($data3)?>;

    $(function() {
    var datasets = [
    {
        label: "Medication",
        data: data1,
        yaxis: 1,
        color: "Yellow",
        points: { symbol: "diamond",  fillColor: "Yellow",show: true, radius: 6}
           
    }
    ];

     $.plot($("#flot-placeholder"), datasets ,options);   
    </script>

This:

    $.plot($("#flot-placeholder"), datasets ,options) don't plot anything

But if I do:
   
    $.plot($("#flot-placeholder"), data3,options);   

I get this graph:

It would be possible to get the graphic writing datasets (in $.plot) instead data3?

Pappas Xristos

unread,
Apr 12, 2016, 12:01:31 PM4/12/16
to flot-...@googlegroups.com
Hello,

data1 javascript array isn't declared. Instead try: data: <?php echo $data1?>

--

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

Reply all
Reply to author
Forward
0 new messages