This topic contains 5 replies, has 2 voices, and was last updated by Sean Sean 3 years, 6 months ago.

Inject JSON from php to charts


  • guytrance
    Participant

    Posts: 8
    Member Reply #1398

    Hi.

     

    I am trying to inject real time data taken from PHP file and put it up  one of the charts for no success.

     

    Here the hirarchy:

    SQL Table in MYSQL -> PHP file whichg renders it to JSON -> Morris.Area receives JSON in ‘data’.

     

    But for some reason nothing i do is going well.

     

    Heres the codes:

     

    PHP:

     

    <?php

     

     

    $dbh = new PDO(“mysql:host=localhost;dbname=yigalbo”, “root”, “”);

    $statement=$dbh->prepare(“SELECT * FROM pdotable”);

    $statement->execute();

    $results=$statement->fetchAll(PDO::FETCH_ASSOC);

    $json=json_encode($results, JSON_PRETTY_PRINT);

     

    header(‘Content-type: application/json’);

     

    echo $json;

    ?>

    here’s the jQuery code:

    var methods = {

    getData: function() {

    return $.ajax({

    ‘global’: false,

    ‘url’: ‘pdo/phpinfo.php’,

    ‘dataType’: ‘json’

    });

    },

    initCharts: function() {

    $.when(methods.getData()).done(function(response) {

    if (Morris.EventEmitter) {

    // Use Morris.Area instead of Morris.Line

    dashboardMainChart = Morris.Area({

    element: ‘sales_statistics’,

    padding: 0,

    behaveLikeLine: false,

    gridEnabled: false,

    gridLineColor: false,

    axes: false,

    fillOpacity: 1,

    data: response,

    lineColors: [‘#399a8c’, ‘#92e9dc’],

    xkey: ‘period’,

    ykeys: [‘sales’, ‘profit’],

    labels: [‘Sales’, ‘Profit’],

    pointSize: 0,

    lineWidth: 0,

    hideHover: ‘auto’,

    resize: true

    });

    }

    });

    }

    };

    What am i doing wrong?

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #1411

    Hi :),

    The approach seems correct. But you may have some JS errors that breaks the chart initialization. Please try to debug your page with Chrome’s dev tools using CTRL + SHIFT + J.

    If you need any further assistance please provide us a test link to your developing site in a private reply(just check “set as a private reply” checkbox) when you submit a reply.

    Thanks.


    guytrance
    Participant

    Posts: 8
    Member Reply #1415
    This reply has been marked as private.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #1467

    Hi,

    Sorry for the late reply.  Just to clarify, did you get it working or you will need an advice ?

    Thanks.


    guytrance
    Participant

    Posts: 8
    Member Reply #1469

    Hey buddy.

     

    Yes i still need help on this i waited for your reply 🙁

     

    Thank you m8

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #1475

    Hi,

    We checked your code and seems this is not a theme issue that our support can cover. In your case you will need an experienced developer’s help in order to implement it as per your unique project requirements. I hope for your understanding. For more info please check our support policy here:

    http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469/support

    Thanks.

Tagged: 

You must be logged in to reply to this topic.