Forum Replies Created by sparky

Viewing 1 post (of 1 total)
  • in reply to: How can I use PHP MySQL Dynamic data #5541

    Hi Sunil, I have tried a lot of things but my graph is still not rendering. I don’t know what could be the problem. jquery not running? or any other issue that I am not aware of.

    Here is my code:

    My data.php file:

    <?php ob_start(); ?>

    <?php
    include ‘core/init.php’;
    protect_page();
    include ‘includes/overall/overallheader.php’;
    ?>

    <h1>Results</h1>

    <?php
    $sql=(“SELECT * FROM users”); {

    $result=mysql_query($sql) or die(“SQL Error 1: ” . mysql_error());
    // get data and store in a json array
    $rows=mysql_fetch_array($result);
    $points[] = array(
    ‘Q1’ => $rows[‘question_1’],
    ‘Q2’ => $rows[‘question_2’],
    ‘Q3’ => $rows[‘question_3’]
    );
    }
    echo json_encode($points, JSON_NUMERIC_CHECK);
    ?>
    <?php
    include ‘includes/overall/overallfooter.php’;
    ?>

    which returns: [{“Q1″:2,”Q2″:3,”Q3″:2}]

    My HTML file

    <!DOCTYPE html>
    <html xmlns=”http://www.w3.org/1999/xhtml&#8221; ><head>
    <title>Graph</title>
    <script src=”/jquery-1.10.2.js”></script>
    <script type=”text/javascript” src=”js/canvasjs.min.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function () {
    $.getJSON(“data.php”, function (result) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    data: [ { dataPoints: result } ]
    });
    chart.render();
    });
    });
    </script>
    </head>
    <body>
    <div id=”chartContainer” style=”width: 800px; height: 380px;”></div>
    </body>
    </html>

    This does not render the graph. I am using Safari and develop in localhost through MAMP environment.

    Thanks in advance for your reply.

Viewing 1 post (of 1 total)