【问题标题】:Binding DataViz chart locally using Angular使用 Angular 在本地绑定 DataViz 图表
【发布时间】:2014-01-03 21:00:37
【问题描述】:

我正在尝试使用 Kendo UI Angular 指令在本地绑定 DataViz 饼图,但一直收到此错误:

TypeError: Cannot call method 'toLowerCase' of undefined
    at h (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:5351)
    at Object.o.aggregate (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:20999)
    at g (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:5624)
    at ct.extend._process (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:31624)
    at ct.extend.success (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:28852)
    at Object.proxy [as success] (http://localhost:51717/Scripts/jquery-1.10.2.js:841:14)
    at ct.extend.read (http://localhost:51717/Scripts/kendo/kendo.web.min.js:11:21673)
    at http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:28381
    at ct.extend._queueRequest (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:30001)
    at ct.extend.read (http://localhost:51717/Scripts/kendo/kendo.dataviz.min.js:11:28266) 

HTML

<div kendo-chart k-options="pie" k-data-source="countries" />

角度

$scope.countries = {
    data: [
        {
            category: "Asia",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America",
            value: 3.6,
            color: "#033939"
        }
    ]
};

$scope.pie = {
    title: {
        position: "bottom",
        text: "Share of Internet Population Growth, 2007 - 2012"
    },
    legend: {
        visible: false
    },
    chartArea: {
        background: ""
    },
    seriesDefaults: {
        labels: {
            visible: true,
            background: "transparent",
            template: "#= category #: #= value#%"
        }
    },
    series: [{
        type: "pie",
        field: "value",
        categoryField: "category"
    }],
    tooltip: {
        visible: true,
        format: "{0}%"
    }
};

【问题讨论】:

  • 您使用的是哪个版本的剑道 UI?您可以添加包含剑道脚本的部分吗?

标签: javascript angularjs kendo-ui kendo-dataviz


【解决方案1】:

检查您的库以确保您使用的是受支持的版本。您使用的是最新版本的 KendoUI 吗?根据KendoUI->Angular repo on GitHub你需要:

  • jQuery v1.9.1(不确定是否支持更高版本)
  • Angular v1.0.5
  • KendoUI vCurrent

我创建了a working example on JSBin 供您查看。代码如下:

<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Angular + KendoUI DataViz" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.all.min.js"></script>
<script src="http://rawgithub.com/kendo-labs/angular-kendo/master/build/angular-kendo.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="chart-example">
  <div ng-controller="ChartController">    
    <div kendo-chart k-options="pie" k-data-source="countries" />
  </div>
</body>
</html>

...

var app = angular.module('chart-example', ['kendo.directives']);

function ChartController($scope) {
  $scope.pie = {
    title: {
        position: "bottom",
        text: "Share of Internet Population Growth, 2007 - 2012"
    },
    legend: {
        visible: false
    },
    chartArea: {
        background: ""
    },
    seriesDefaults: {
        labels: {
            visible: true,
            background: "transparent",
            template: "#= category #: #= value#%"
        }
    },
    series: [{
        type: "pie",
        field: "value",
        categoryField: "category"
    }],
    tooltip: {
        visible: true,
        format: "{0}%"
    }
  };

  $scope.countries = {
    data: [
        {
            category: "Asia",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America",
            value: 3.6,
            color: "#033939"
        }
    ]
  };
}

【讨论】:

  • 切换我的脚本引用以使用 kendo.all.min.js 修复了它。我只引用了 kendo.dataviz 和 kendo.ui。
  • 工作示例不工作。我正在尝试使用它来学习如何在角度中使用 dataviz,但是出了点问题...
猜你喜欢
  • 2014-01-27
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 2021-07-19
相关资源
最近更新 更多