Home Forums Chart Support Date in xValue – Don’t Show.

Date in xValue – Don’t Show.

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

    Please, I can’t use my date in the xvalue of my graph.

    $dataPoints = array();
    $result = json_decode($response->getBody(), true);
    foreach($result as $row){
    
    		$date = date("M j G:i:s", strtotime($row['created_at']));
    		array_push($dataPoints, array("x"=> $date, "y"=> $row['responseTime']));
        }

    #39467

    @g3nius,

    To pass date as x-value using PHP, you need to first convert PHP date to PHP timestamp using strtotime and then convert PHP timestamp to JavaScript timestamp by multiplying PHP timestamp by 1000. Along with passing the timestamp as x value, you need to set xValueType option to ‘dateTime’ in dataseries.

    foreach($result as $row){
      array_push($dataPoints, array("x"=> strtotime($row['created_at']) * 1000, "y"=> $row['responseTime']));
    }

    —-
    Manoj Mohan
    Team CanvasJS

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

You must be logged in to reply to this topic.