Home Forums Chart Support Assign JSON object to a variable

Assign JSON object to a variable

Viewing 2 posts - 1 through 2 (of 2 total)
  • #28373

    Im trying to assign a json object to a variable. Im not sure how to accomplish this.
    This is my JSON array:
    [{“Date”:”2020-01-24 07:35:46″,”sensorName”:”sensor 1″,”sensorValue”:213},{“Date”:”2020-01-24 07:35:46″,”sensorName”:”sensor 1″,”sensorValue”:433},{“Date”:”2020-02-10 06:03:36″,”sensorName”:”sensor 1″,”sensorValue”:321},{“Date”:”2020-02-10 06:03:36″,”sensorName”:”sensor 1″,”sensorValue”:43},{“Date”:”2020-02-12 03:30:57″,”sensorName”:”sensor 1″,”sensorValue”:4321}]

    I wish to assign the value of sensorValue to variable yValue. how do i do this?

    Below code snippet is in javascript. Cant seem to upload my codes properly.
    the brackets for php was replaced with ( instead of <?.
    `
    var sensor1 = (php echo json_encode($json_sensor1, JSON_NUMERIC_CHECK); );
    var sensor2 = (php echo json_encode($json_sensor2, JSON_NUMERIC_CHECK); );

    var yValue1 = sensor1.sensorValue;
    var yValue2 = sensor2.sensorValue;
    var xValue = sensor1.Date;
    `

    #28382

    @mrt4c,

    Please take a look at this updated sample project.

    Considering this as a duplicate of using json array from php json_encode hence closing the same.


    Shashi Ranjan
    Team CanvasJS

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

You must be logged in to reply to this topic.