Home Forums Chart Support Add title with parameter when calling php page

Add title with parameter when calling php page

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

    Hello,

    i am new to PHP and canvasjs.
    I would like to fill in the title field in the chart definition comming from a parameter when calling the php page.
    i could not get it working …

    anybody here that can help me ?

    <?php
    $conn = new mysqli(“192.168.3.9”, “marc”, “marc”, “sensors”);
    $dataPoints = array();
    $table = $_GET[‘table’];
    $title = $_GET[‘title’];

    if ($conn->connect_error) {
    die(“ERROR: Unable to connect: ” . $conn->connect_error);
    }
    //echo ‘Connected to the database.<br>’;
    $result = $conn->query(“SELECT * FROM $table”);
    //echo “Number of rows: $result->num_rows”.”<br>”;

    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $y = $row[“temp”];
    $t = $row[“time”];
    $u = strtotime($t) * 1000;
    array_push($dataPoints, array(“x” => $u, “y” => $y));
    }
    } else {
    echo “0 results”;
    }

    $result->close();

    $conn->close();
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <script>
    window.onload = function () {

    var chart = new CanvasJS.Chart(“chartContainer”, {
    theme: “light2”, // “light1”, “light2”, “dark1”, “dark2”
    animationEnabled: true,
    zoomEnabled: true,
    zoomType: “xy”,
    exportEnabled: true,
    title: {
    text: $title
    },
    axisX: {
    valueFormatString: “DD/MM/YY HH:mm”,
    labelAngle: 135
    },
    axisY: {
    title: “Temperature”,
    prefix: “”,
    suffix: “°”,
    lineThickness: 1,
    lineColor: “brown”,
    //gridColor: “black”,
    minimum: -20,
    maximum: 45,
    gridThickness: 1,
    margin: 5,
    interval: 5

    },
    toolTip:{
    content:”{x} {y}°”,
    backgroundColor: “#f4d5a6”,
    cornerRadius: 4
    },
    data: [{
    type: “line”,
    color: “darkblue”,
    xValueType: “dateTime”,
    xValueFormatString: “DD/MM/YY HH:mm”,
    dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
    }]
    });
    chart.render();
    }
    </script>
    </head>
    <body>
    <div id=”chartContainer” style=”height: 370px; max-width: 920px; margin: 10px auto;”></div>
    <script src=”http://www.woeper.be/canvas/canvasjs.min.js”></script&gt;
    </body>
    </html>

    #26735

    @woeperbe,

    Changing text: $title to text:<?php $title ?> should work fine in your case.

    If the issue still persists, kindly share sample project along with sample data over Google-Drive or Onedrive so that we can run it locally at our end to understand the scenario better and help you resolve.


    Vishwas R
    Team CanvasJS

    #26933

    Hello,

    When i do this the graph is not displayed anymore …..

    #26939

    @woeperbe,

    Can you kindly share sample project with sample data over Google-Drive or Onedrive so that we can run it locally at our end to understand the issue you are facing and help you resolve?


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.