我正在使用mean.io启动项目,我正在尝试使用zingchart显示图表。
当我检查我的代码时,我看到一个zingchart没有定义错误,看起来像这样。
我是使用mean.io.的新手 我还要提一下,这是在我创建的一个名为" dashboard"
的新软件包中发生的。这是我的控制器(dashboard.js):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="winner-container">
<div class="top">
<h4 class="headline">SME Example 1</h4>
</div>
<div class="bottom">
<div class="winner-words">
<h6>SME Examle 1 is a technology company.</h6>
<h6><a>Learn more...</a></h6>
</div>
</div>
</div>
<div class="winner-container">
<div class="top">
<h4 class="headline">SME Example 2</h4>
</div>
<div class="bottom">
<div class="winner-words">
<h6>SME Examle 2 is an e-commerce company.</h6>
<h6><a>Learn more...</a></h6>
</div>
</div>
</div>
我的html文件(index.html):
(function() {
'use strict';
/* jshint -W098 */
angular
.module('mean.dashboard', ['zingchart-angularjs'])
.controller('DashboardController', function($scope) {
$scope.myJson = {
type : 'line',
series : [
{ values : [54,23,34,23,43] },
{ values : [10,15,16,20,40] }
]
};
});
})();
我的app.js文件:
<html ng-app="mean.dashboard" ng-init="checkCircle()">
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="zingchart.min.js"></script>
<script type="text/javascript" src="zingchart-angularjs.js"></script>
<script src="dashboard.js"></script>
<body ng-controller="DashboardController" ng-cloak layout="column">
<!-- graph here -->
<h1>Graph Test</h1>
<div ng-controller="DashboardController">
<div zingchart id="myChart" zc-json="myJson" zc-height=500 zc-width=600></div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
使用您的代码我看到很多问题,让我简化您的代码并显示错误,
<html ng-app="mean.dashboard" ng-init="checkCircle()">
你不能在html中使用ng-init,它需要放在body中,同时ng-controllers也是重复的。你只需要在一个地方拥有它。
查看下面的演示
<强>演示强>
(function() {
'use strict';
angular
.module('mean.dashboard', ['zingchart-angularjs'])
.controller('DashboardController', function($scope) {
$scope.myJson = {
type : 'line',
series : [
{ values : [54,23,34,23,43] },
{ values : [10,15,16,20,40] }
]
};
});
})();
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/374756/zingchart-2.2.2.min.js"></script>
<script src= "https://s3-us-west-2.amazonaws.com/s.cdpn.io/374756/zingchart-angularjs-1.0.4.js"></script>
<body ng-app="mean.dashboard">
<div ng-controller="DashboardController" id="resizable">
<div zingchart id="chart-1" zc-json="myJson" zc-width="100%" zc-height="100%"></div>
</div>
</body>
答案 1 :(得分:0)
如果有其他人遇到此问题或类似问题,我会发布我的答案。
在要添加zingchart依赖关系的包/文件夹中,或者任何依赖关系,你必须像这样将它添加到你的bower.json文件中。
{
"name": "packagename",
"version": "0.0.1",
"dependencies": {
"zingchart-angularjs": "latest" <!--dependency-->
}
}
然后在你的app.js文件中你需要像这样注册zingchart依赖
'use strict';
/*
* Defining the Package
*/
var Module = require('meanio').Module;
var packagename= new Module('packagename');
/*
* All MEAN packages require registration
* Dependency injection is used to define required modules
*/
packagename.register(function(app, auth, database, circles) {
//We enable routing. By default the Package Object is passed to the routes
packagename.routes(app, auth, database, circles);
//register dependencies
packagename.angularDependencies(['zingchart-angularjs']);
return packagename;
});
然后您需要确保zingchart依赖库在此路径/ public / assets / lib中包含,并确保在.bowerrc文件中正确引用此路径
{
"directory": "public/assets/lib"
}
然后你可以继续添加在controller.js文件中创建并呈现实际图表的代码
(function() {
'use strict';
angular
.module('mean.packagename', ['zingchart-angularjs'])
.controller('AppController', function($scope) {
$scope.myJson = {
type : 'line',
series : [
{ values : [54,23,34,23,43] },
{ values : [10,15,16,20,40] }
]
};
});
})();
最后,您可以像这样
在html文件中引用此代码<body ng-app="mean.dashboard">
<div ng-controller="AppController" id="resizable">
<div zingchart id="chart-1" zc-json="myJson" zc-width="100%" zc-height="100%"></div>
</div>
</body>