Home forums Report Bugs Generate chart with database data

This topic contains 3 replies, has 4 voices, and was last updated by  Sunil Urs 1 year, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9172

    Nimal
    Member

    Hi plz help, I tried to generate a chart using database data but it doesn’t work
    Html…………
    <!DOCTYPE html>
    <html >
    <head>
    <title>Untitled Document</title>
    <script type=”text/javascript” src=”canvasjs.min.js”></script>
    <script src=”source/jquery.js”></script>
    <script type=”text/javascript” src=”source/canvasjs.js”></script>
    <script type=”text/javascript”>
    $(document).(function () {
    $.getJSON(“data.php”, function (result) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    data: [
    {
    dataPoints: result
    }
    ]
    });
    chart.render();
    });
    });
    </script>
    </head>
    <body>
    <title></title>
    </body>
    </html>

    PHP……………………..
    <?php
    $servername = “localhost”;
    $username = “root”;
    $password = “”;
    $dbname = “assignment2”;
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {
    die(“Connection failed: ” . $conn->connect_error);
    }
    header(‘Content-Type: application/json’);
    $data_points = array();
    $sql = “SELECT * FROM power1 sales”;
    $result = mysqli_query($conn,$sql);
    if (!$result) {
    echo ‘MySQL Error: ‘ . mysqli_error($conn);
    }
    ;
    while($row = mysqli_fetch_array($result))
    {
    $point = array(“label” => $row[‘product’] , “y” => $row[‘total_sales’]);
    array_push($data_points, $point);
    }
    echo json_encode($data_points, JSON_NUMERIC_CHECK);
    mysqli_close($con);
    ?>

    #9179

    Anjali
    Participant

    Nimal,

    Can you please provide a sample JSON data so that we can suggest a solution.

    __
    Anjali

    #9460

    dayanasanjay
    Member

    i have same issue its not working for me also.

    #9465

    Sunil Urs
    Keymaster

    dayanasanjay,

    If you can post your code and the error that you are getting we can have a look.


    Sunil Urs

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.