score:27

Accepted answer

i think you cannot return values from the success call instead you would need to call a function instead. so set up your function that initializes your chart, and in the ajax success call that function with the data

with your code example

function visitordata (data) {
   $('#chart1').highcharts({
    chart: {
        type: 'column'
    },
    title: {
        text: 'average visitors'
    },
    xaxis: {
        categories: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
    },
    yaxis: {
        title: {
            text: 'number of visitors'
        }
    },
    series: data,
  });
}
$(document).ready(function() {
 $.ajax({
    url: '/visitdata',
    type: 'get',
    async: true,
    datatype: "json",
    success: function (data) {
        visitordata(data);
    }
  });
 });

score:1

//parse json response
var chartseriesdata = [];
var chartcategory = [];

$.each(response, function() {

  if(this.name!="total" && this.no!="0") {

    var series_name = this.name;
    var series_data = this.no;

    var series = [
      series_name,
      parsefloat(series_data)
    ];
    chartseriesdata.push(series);   
  }
});

//initialize options for highchart
var options = {
  chart: {
    plotbackgroundcolor: null,
    plotborderwidth: null,
    plotshadow: false
  },
  title: {
    text: 'salesorder '
  },
  tooltip: {
    pointformat: '{series.name}: <b>{point.y}</b>'
  },
  plotoptions: {
    pie: {
      allowpointselect: true,
      cursor: 'pointer',
      center:['60%','60%'],
      size:150
      ,
      datalabels: {
        enabled: true,
        color: '#000000',
        distance: 40,
        connectorcolor: '#000000',
        format: '<b>{point.name}</b>: {point.y} '
      }
    }
  },
  series: [{
    type: 'pie',
    name: 'browser share',
    data:chartseriesdata //load array created from json
  }]
}

//options.series[0].setdata(datavaluejson);
var chart= $('#container').highcharts(options);

score:2

in your ajax success function call your visitordata function with data[1].data (since that's how your json is formatted)

    $.ajax({
        url: '/visitdata',
        type: 'get',
        async: true,
        datatype: "json",
        success: function (data) {
            visitordata(data[1].data);

        }
    });

also, your visitordata function def is odd.

vistordata = function(data) 

or

function vistordata(data)

Related Query