Home Forums Chart Support candlestick chart with mysql

candlestick chart with mysql

Viewing 4 posts - 1 through 4 (of 4 total)
  • #13580

    hello everyone, my name is rizki,really need help,
    i want to make candlestick from mysql and show it to the page
    ihave one table named harga consist of id,open,low,close,high

    this is the data.php to take the value from mysql

    <?php

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

    $con = mysqli_connect(“127.0.0.1″,”root”,””,”saham”);

    // Check connection
    if (mysqli_connect_errno($con))
    {
    echo “Failed to connect to DataBase: ” . mysqli_connect_error();
    }else
    {
    $data_points = array();

    $result = mysqli_query($con, “SELECT * FROM harga”);

    while($row = mysqli_fetch_array($result))
    {
    $point = array(“x” => $row[‘tanggal’] , “y” => $row[‘open’],$row[‘low’],$row[‘high’],$row[‘close’]);

    array_push($data_points, $point);
    }

    echo json_encode($data_points, JSON_NUMERIC_CHECK);
    }
    mysqli_close($con);

    ?>

    and this is web page

    <!DOCTYPE HTML>
    <html>
    <head>
    <script type=”text/javascript”>
    $(document).ready(function () {

    $.getJSON(“data.php”, function (result) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    title: {
    text: “Basic Candle Stick Chart”
    },
    zoomEnabled: true,
    axisY: {
    includeZero: false,
    title: “Prices”,
    prefix: “$ ”
    },
    axisX: {
    interval: 2,
    intervalType: “month”,
    valueFormatString: “MMM-YY”,
    },
    data: [
    {
    type: “candlestick”,
    dataPoints: result

    }
    ]
    });
    chart.render();
    }
    </script>
    <script src=”../../canvasjs.min.js”></script>
    <title>CanvasJS Example</title>
    </head>
    <body>
    <div id=”chartContainer” style=”height: 400px; width: 100%;”>
    </div>
    </body>
    </html>

    i am really stuck did not know what to do,really need help,thanks in advance

    #13581

    kiukiu

    What is the problem that you are facing? Are you getting some error?

    • This reply was modified 7 years, 11 months ago by Bivek Singh.
    #13582

    Thanks Bivek Singh,
    I have try it but did not work,the real problem is the chart not reloading and the page just in blank,,
    hope any solution then,,

    #13584

    kiukiu

    data_points must be array of objects. So, each element inside an array must be an object.
    y value should be an array of 4 values not just comma separated value.

    Also, try with following things and check if there is some error:

    -> echo $result and see if it is returning a value from DB
    -> echo $data_points to check if you have the value in prescribed format.

    • This reply was modified 7 years, 11 months ago by Bivek Singh.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.