Thanks Andrew. It worked with the correction that you mentioned. It was the static data which is working. However, I want a JSON file similar to the above one to be generated from the data fetched from database. I am working with PHP and MYSQL. When i run a select query and generate the PHP file i observed that there are few things missing in the JSON file. Also guess may be because of that the graph was also not getting generated, instead a blank page was displayed.
<?php
$cal_st_date = '2014-10-2';
$cal_end_date = '2014-10-9';
$gph_values = array();
include 'db.php';
$fetch_rows = mysql_query("SELECT cg.attach_doc_path,cg.start_date,cg.end_date,cg.coupon_upc,cg.coupon_type FROM CPNS_TESTING cg,CPNS_TESTED ct where cg.cpn_id=ct.coupon_id and ct.approved='Y' and ct.valid='T' and cg.end_date >= '$cal_st_date' group by cg.cpn_id");
$num_rows = mysql_num_rows($fetch_rows);
echo $num_rows;
while($row = mysql_fetch_array($fetch_rows))
{
$row_array['file']= $row['attach_doc_path'];
$row_array['upc'] = $row['coupon_upc'];
$row_array['Cpn_type'] = $row['coupon_type'];
$start_date = $row['start_date'];
$str_start_date = strtotime($start_date);
$str_cal_start_date = strtotime($cal_st_date);
if($str_start_date >= $str_cal_start_date)
{
$arr_start_date = explode("-",$start_date);
$arr_start_date = $arr_start_date[0].",".$arr_start_date[1].",".$arr_start_date[2];
$row_array['start_date'] = $arr_start_date;
}
else
{
$arr_start_date = explode("-",$cal_st_date);
$arr_start_date = $arr_start_date[0].",".$arr_start_date[1].",".$arr_start_date[2];
$row_array['start_date'] = $arr_start_date;
}
$end_date = $row['end_date'];
$str_end_date = strtotime($end_date);
$str_cal_end_date = strtotime($cal_end_date);
if($str_end_date >= $str_cal_end_date)
{
//$arr_end_date = $cal_end_date;
$arr_end_date = explode("-",$cal_end_date);
$arr_end_date = $arr_end_date[0].",".$arr_end_date[1].",".$arr_end_date[2];
$row_array['end_date'] = $arr_end_date;
}
else
{
//$arr_end_date = $end_date;
$arr_end_date = explode("-",$end_date);
$arr_end_date = $arr_end_date[0].",".$arr_end_date[1].",".$arr_end_date[2];
$row_array['end_date'] = $arr_end_date;
}
$text = $upc . "-". $type;
array_push($gph_values,$row_array);
}
//echo json_encode($gph_values);
$fp = fopen('C:\XAMP\htdocs\graph\sampleData.json', 'w+');
fwrite($fp, json_encode($gph_values));
fclose($fp);