Home Forums Chart Support Add axisY StripLines to array push issue

Add axisY StripLines to array push issue

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

    I’m trying to figure out how to add a few elements to my charts using PHP/json array push; Namely, a Title and the AxisY striplines.

    When I render the chart, my datapoints look like they are populating just fine, so I’m not sure what is happening.

    dataPoints: [{“label”:”2019-03-25 08:40:00″,”y”:1.1,”name”:”Phosphorus”,”ylineA”:2.5,”ylineB”:4.5},{“label”:”2019-03-26 05:43:00″,”y”:2.5,”name”:”Phosphorus”,”ylineA”:2.5,”ylineB”:4.5}] }]

    $path = $_SERVER[‘DOCUMENT_ROOT’];
    $path .= “xxx”;

    $tID = mysqli_real_escape_string($link, $_GET[‘id’]);

    $sql = “SELECT *
    FROM tbl_test_results tr

    LEFT JOIN tbl_test t
    ON tr.testID = t.testID

    WHERE tr.testID = ‘$tID’

    ORDER BY datetime_collected ASC

    $data = $link->query($sql);
    $dataPoints = array();

    if ($data->num_rows > 0) {

    while($row = $data->fetch_assoc()) {
    $point = array(“label” => $row[‘datetime_collected’], “y” => $row[‘test_result’], “name” => $row[‘test_name’], “ylineA” => $row[‘test_low’], “ylineB” => $row[‘test_high’]);
    array_push($dataPoints, $point);


    <div id=”chartContainer2″ style=”width: 100%; height: 300px;”></div>

    <script type=”text/javascript”>

    $(function () {

    [//colorSet Array

    var chart2 = new CanvasJS.Chart(“chartContainer2”, {
    zoomEnabled: false,
    animationEnabled: true,
    colorSet: “blueShades2”,
    text: “{name}”
    toolTip:{content: “{name}: {y}”},
    data: [{
    type: “line”,
    indexLabelFontSize: 14,
    indexLabel: “{y}”,
    indexLabelPlacement: “outside”,
    indexLabelOrientation: “horizontal”,
    dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>




    The startValue and endValue of stripLine should be numbers. Kindly check if the ylineA and ylineB that you are passing are numbers if not typecasting it to number should work fine. If you are still facing the issue, can you please share the sample project reproducing the same over Google Drive/One Drive so that we can look into the code, understand it better and help you out.

    Shashi Ranjan
    Team CanvasJS


    Hi Shashi- Thanks for your reply.

    Yes, I can confirm that the values ylineA and ylineB are numbers.

    Here is a sample project that you may peruse. It is the same code that is listed in the body of this message above.
    to see a live working version you may visit temporarily,

    Let me know if you have any further thoughts or need further information.



    The values ylineA and ylineB that you are trying to pass as startValue and endValue are basically an element within $datapoints array. But you are trying to access it directly, which would be undefined. Accessing the values properly should work fine in this case.

    If the issue still persists, kindly share a working sample project along with sample database so that we can run it locally at our end to help you fix the issue.

    Shashi Ranjan
    Team CanvasJS

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

You must be logged in to reply to this topic.