Home Forums Chart Support using json array from php json_encode Reply To: using json array from php json_encode

#28295

@mrt4c,

When you have a JSON array it is very easy to generate charts from them. Let’s consider you have a JSON array in this format:

[	
    [
      1483275269000,
      10
    ],
    [
      1483361668000,
      12
    ],
    [
      1483448068000,
      17
    ],
    [
      1483534467000,
      11
    ],
    [
      1483620867000,
      13
    ],
]

Now, you need to parse the data in the format accepted by CanvasJS to use them as dataPoints and generate a chart. Please refer to the code snippet below for an example:

[  
  { 
    x: new Date(1483275269000),  
    y: 10
  }, 
  {
    x: new Date(1483275268000), 
    y: 12
  },
  {
    x: new Date(1483448068000), 
    y: 17
  },
  {
    x: new Date(1483534467000), 
    y: 11
  } 
]

You can also take a look at this gallery page for an example on creating a chart using JSON data in PHP.

PHP Charts & Graphs from JSON Data Using AJAX


Shashi Ranjan
Team CanvasJS