Php 如何在Highchart中获得ajax数据数组的响应

Php 如何在Highchart中获得ajax数据数组的响应,php,jquery,ajax,highcharts,Php,Jquery,Ajax,Highcharts,我试图使用ajax获得json数据响应,但无法得到结果。 我将得到如下错误。 未捕获的TypeError:无法读取未定义的属性“0” 我的简单图表数据如下 <script type="text/javascript"> $(function () { $(document).ready(function() { var chart; chart = $('#container2').highcharts({ title: {

我试图使用ajax获得json数据响应,但无法得到结果。 我将得到如下错误。 未捕获的TypeError:无法读取未定义的属性“0”

我的简单图表数据如下

<script type="text/javascript">
$(function () {
$(document).ready(function() {
    var chart;
      chart = $('#container2').highcharts({

            title: {
                text: 'Monthly Average Backing',
                x: -20 //center
            },

            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },
            yAxis: {
                title: {
                    text: 'Backing ($)'

                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },

            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: <?php echo json_encode($array); ?>
        });
    });

});
        </script> 
所以我只想更新我的图表,这里是我的ajax调用:

$.ajax({
                type: "POST",
                url: "user/ajax.profile.statistics.php?action=custommap",
    data:{categoryId:categoryId,pricelowrange:pricelowrange,pricehighrange:pricehighrange,successsort:successsort,datefrom:datefrom,dateto:dateto,sortingautosuggest:sortingautosuggest,timefrom:timefrom,timeto:timeto},
                async:false,
                dataType:'json',
                cache: false,
                success: function(dataRes)
                                {
                                    **chart.series[0]**.setData(dataRes['data'],true)

                                }


            });
我只希望我的回复数据在图表中


未捕获的TypeError:无法读取未定义的属性“0”

请尝试在ajax中使用回调选项和url

$.ajax({
                type: "POST",
                url: "user/ajax.profile.statistics.php?callback=",
    data:{categoryId:categoryId,pricelowrange:pricelowrange,pricehighrange:pricehighrange,successsort:successsort,datefrom:datefrom,dateto:dateto,sortingautosuggest:sortingautosuggest,timefrom:timefrom,timeto:timeto},
                async:false,
                dataType:'jsonp',
                cache: false,
                data:{data:JSON.stringify([{action:'custommap'}])},
                success: function(dataRes)
                {       alert(dataRes);
                        <?php echo json_encode($array); ?>

                }

            });
$.ajax({
类型:“POST”,
url:“user/ajax.profile.statistics.php?callback=”,
数据:{categoryId:categoryId,pricelowrange:pricelowrange,pricehighrange:pricehighrange,successsort:successsort,datefrom:datefrom,dateto:dateto,sortingautosuggest:sortingautosuggest,timefrom:timefrom,timeto:timeto},
async:false,
数据类型:'jsonp',
cache:false,
数据:{data:JSON.stringify([{action:'custommap'}])},
成功:函数(dataRes)
{警报(数据资源);
}
});
下面的博客将帮助你


数组中有对象。所以你需要像那样访问它

dataRes[0]['name']
dataRes[0]['data']
您的代码应该是这样来访问数据的

        $.ajax({
                type: "POST",
                url: "user/ajax.profile.statistics.php?action=custommap",
    data:{categoryId:categoryId,pricelowrange:pricelowrange,pricehighrange:pricehighrange,successsort:successsort,datefrom:datefrom,dateto:dateto,sortingautosuggest:sortingautosuggest,timefrom:timefrom,timeto:timeto},
                async:false,
                dataType:'json',
                cache: false,
                success: function(dataRes)
                {      
                   console.log(dataRes[0]['name']);
                   console.log(dataRes[0]['data'])
                }

            });
当您有可用数据时,您可以重新绘制/重置海图。 要在此处重新绘制检查api引用,请执行以下操作:


JSFIDLE:

如果有任何错误或其他什么,这个url:user/ajax.profile.statistics.php?action=custommap返回什么。@ABHISHEK:-不,没有任何错误。事实上,我也得到了我的ajax响应。但现在如何将其应用到Ajax的成功中现在请检查我的答案。通过这种方式,您可以在回调中访问数据。您应该在ajax回调中初始化/更新您的图表数字手表心率监视器[0,0,0,180,0,0,0,0]好。现在我获得了nama和数据数组,但现在如何根据数据更新我的图表ok感谢anwser,但对于添加系列,我想使用ajax重新绘制我的图表。现在我从你的anwser得到了更多信息,我更新了我的问题,请检查并帮助我,如果它解决了问题,那么我只得到一个错误,它100%工作。爱欲如下文所述。未捕获的TypeError:无法读取undefinedIt的属性“0”,意味着您正在对不存在的数据进行循环。
        $.ajax({
                type: "POST",
                url: "user/ajax.profile.statistics.php?action=custommap",
    data:{categoryId:categoryId,pricelowrange:pricelowrange,pricehighrange:pricehighrange,successsort:successsort,datefrom:datefrom,dateto:dateto,sortingautosuggest:sortingautosuggest,timefrom:timefrom,timeto:timeto},
                async:false,
                dataType:'json',
                cache: false,
                success: function(dataRes)
                {      
                   console.log(dataRes[0]['name']);
                   console.log(dataRes[0]['data'])
                }

            });