Angularjs和谷歌图表api:图表类型未定义

时间:2015-10-08 16:13:36

标签: javascript angularjs charts google-visualization

我正在开发一个Web应用程序(Angularjs-J2EE)。在主页上,我正在显示一个图表。 当我在启动服务器(Tomcat)后第一次点击此主页时,我收到此错误:

  

由于错误而未显示图表:未定义图表类型..完整   错误对象如下。 ng-google-chart.js:197对象{id:   “google-visualization-errors-0”,消息:“图表类型不是   所定义。“}

如果我刷新主页,我就不再有这个错误了。图表显示良好 如果有人知道为什么......

感谢。

控制器:

$scope.chartObject = {type:"PieChart"};
var datas = CaNetPieChart.query(function(){
  $scope.chartObject.data = {"cols": [
          {id: "t", label: "Article", type: "string"},
          {id: "s", label: "Colis", type: "number"}
      ], "rows": [
          {c: [
              {v: "CA Net"},
              {v: datas[0].valeur},
          ]},
          {c: [
              {v: "CA Net N-1"},
              {v: datas[1].valeur}
          ]}
      ]};
      $scope.chartObject.type = "PieChart";
      $scope.chartObject.options = {
          'backgroundColor': '#f5f5f5',
          'title': "Comparaison CA et CA N-1" ,'height':"200"  
      }
});

和HTML:

<div class="col-md-6" >
    <div google-chart chart="chartObject" style="{{chart.cssStyle}}"/>
</div>

1 个答案:

答案 0 :(得分:0)

试试这段代码。

$scope.loanchart = function(){
    $scope.chartObject = {};

    $scope.chartObject.data = {"cols": [
        {id: "t", label: "Topping", type: "string"},
        {id: "s", label: "Slices", type: "number"}
    ], "rows": [
        {c: [
            {v: "Mushrooms"},
            {v: 3},
        ]},
        {c: [
            {v: "Olives"},
            {v: 31}
        ]},
        {c: [
            {v: "Zucchini"},
            {v: 5},
        ]}
    ]};
    $scope.chartObject.type = "PieChart";
    $scope.chartObject.options = {
        'title': 'How Much Pizza I Ate Last Night'
    };
  };