Home forums Report Bugs json format for new date

This topic contains 0 replies, has 1 voice, and was last updated by  kennymatthew 1 year, 5 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #9155

    kennymatthew
    Member

    Hi,

    ` <script type=”text/javascript”>
    window.onload = function () { var weekly = new CanvasJS.Chart(“weekly”,
    {
    title:{
    text: “Weekly Fruit and Veg Consumption”
    },
    axisY:{
    title:”Total”
    },
    axisX:{
    title: “week”,
    valueFormatString: “DD-MMM” ,
    labelAngle: -50
    },
    animationEnabled: true,
    data: [
    {
    type: “stackedColumn”,
    toolTipContent: “{label}{x}<br/><span style=’\”‘color: {color};’\”‘><strong>{name}</strong></span>: {y} portions”,
    name: “Fruit”,
    showInLegend: “true”,
    dataPoints: [
    { x: new Date(“2015, June, 16”), y: 2},
    { x: new Date(“2015, June , 19”), y: 5 },
    { x: new Date(“2015, June , 20”), y: 5 },

    ]
    }, {
    type: “stackedColumn”,
    toolTipContent: “{label}{x}<br/><span style=’\”‘color: {color};’\”‘><strong>{name}</strong></span>: {y} portions”,
    name: “Vegetable”,
    showInLegend: “true”,
    dataPoints: [
    { x: new Date(“2015, June, 16”), y: 1},
    { x: new Date(“2015, June, 19”), y: 1 },
    { x: new Date(“2015, June, 20″), y: 1 }

    ]
    }
    ]
    ,
    legend:{
    cursor:”pointer”,
    itemclick: function(e) {
    if (typeof (e.dataSeries.visible) === “undefined” || e.dataSeries.visible) {
    e.dataSeries.visible = false;
    }
    else
    {
    e.dataSeries.visible = true;
    }
    weekly.render();
    }
    }
    });

    weekly.render();
    weekly = {};
    }
    </script>`

    in my data.php page

          
    if (mysql_num_rows($registerquery)!=0)
    {
            $a='['; 
    
            while($fvarray = mysql_fetch_row($registerquery))
                {
                    $a.= '{"x":"new Date('.$fvarray[0].')","fruit":"'.$fvarray[1].'","veg":"'.$fvarray[2].'"},';
    
                }
    
             $a=substr($a,0,strlen($a)-1);      
            $a.=']';
    
                 echo $a;
       
      }

    this gives me an output in this format ….

    
    [
        {
            "x": "new Date(2015-06-29)",
            "fruit": "11",
            "veg": "11"
        },
        {
            "x": "new Date(2015-06-30)",
            "fruit": "2",
            "veg": "2"
        }
    ]

    Could you please tell me if this is the correct way to make the Json format for new date and if so ..how do i use this json data into my html page. Currently i am using static data

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.