【问题标题】:Highchart not rendering inside a ajax function angularjsHighchart没有在ajax函数angularjs中呈现
【发布时间】:2018-07-08 13:55:12
【问题描述】:

Highchart 不呈现来自 ajax 调用的数据。如果我在 $http 函数之外使用静态数据,highchart 正在呈现。高位图表未触发。

html:

  <hc-pie-chart title="Browser usage" data="pieData">Placeholder for pie chart</hc-pie-chart>

控制器:

$scope.homeallpcn = function(){
  var url = "homechartall";
  var data = "";
  $http.get(url).then( function(response) {
    $scope.pieData = [{
                    name: "Cancelled",
                    y: response.c
                }, {
                    name: "Closed",
                    y: response.cl,
                    sliced: true,
                    selected: true
                }, {
                    name: "Open",
                    y: response.o
                }, {
                    name: "Rejected",
                    y: response.r
              }]

  });


}
$scope.homeallpcn();

服务:

mainApp.directive('hcPieChart', function () {
            return {
                restrict: 'E',
                template: '<div></div>',
                scope: {
                    title: '@',
                    data: '='
                },
                link: function (scope, element) {
                    Highcharts.chart(element[0], {
                        chart: {
                            type: 'pie'
                        },
                        title: {
                            text: scope.title
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                                }
                            }
                        },
                        series: [{
                            data: scope.data
                        }]
                    });
                }
            };
        })

请给我建议。

【问题讨论】:

  • 请创建一个现场演示。如果先创建图表,然后再创建数据,则使用 series.setData 进行动态更新。

标签: angularjs highcharts


【解决方案1】:

一些建议:

1 - 通话后console.log(response) 真的显示数据吗?

2 - 请记住 pie 不能用于字符串数据,因此 response.cresponse.oresponse.r 必须是整数或浮点数。

【讨论】:

  • 感谢您的回复。数据正在响应。使用静态数据本身,highchart 不会在 ajax 调用中触发
猜你喜欢
  • 1970-01-01
  • 2016-03-15
  • 2013-10-21
  • 2021-04-09
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
相关资源
最近更新 更多