0

i was trying with flot area chart for statistical data over year, but everything is fine with static data, now i want to fetch data from mysql but couldn't able to fetch from json properly...

//ajax response
$.post('fetch_data.php',{table:enq},function(data){
    alert('response: '+data);
    //response = [{"year":"2010","Nos":"3"},{"year":"2012","Nos":"7"},{"year":"2014","Nos":"5"}]                    
});
//static data
var d1 = [[2010, 3], [2012, 7], [2014, 5]];
var data1 = [
    {  data: d1, points: { fillColor: "#3c8dbc", size: 5 }, color: '#3c8dbc' }
];

$.plot($("#placeholder"), data1, {
    xaxis: {
        axisLabel: 'Year',
        axisLabelUseCanvas: true,
        axisLabelFontSizePixels: 12,
        axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
        axisLabelPadding: 5, tickLength: 0
    },
    yaxis: {
        min: 0,
        max: 10000,
        axisLabel: 'Amount',
        axisLabelUseCanvas: true,
        axisLabelFontSizePixels: 12,
        axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
        axisLabelPadding: 5
    },
    series: {
        lines: {
            show: true,
            fill: true
        },
        stack: true,
        points: {
            show: false
        },
        shadowSize: 7, // Drawing is faster without shadows
        color: "#3c8dbc"
    },
    grid: {
        borderWidth: 1
    }/*,
    legend: {
        labelBoxBorderColor: "none",
        position: "right"
    } */
});

so how to format ajax response to look similar to the static data which i have mentioned... tried this but of no avail...

Community
  • 1
  • 1
x-code
  • 608
  • 1
  • 10
  • 30

1 Answers1

0

got this solved... :)

    $.post('fetch_data.php',{},function(data)
    {
       var obj = JSON.parse(data);
       var main_arr=[];
       if(obj.length >0)
       {
          var arr = [];
          $.each(obj,function () {
              arr = [this.Year, this.Nos];
              main_arr.push(arr);
           })
        }
        alert(main_arr);
        // then proceed plotting the chart...
   });
x-code
  • 608
  • 1
  • 10
  • 30