I'm working with the mean.io starter project and I am trying to get a chart to display using zingchart.
When I inspect my code, I see a zingchart not defined error that looks like this.
I am new to using mean.io.
I should also mention that this is taking place in a new package that I created called "dashboard"
Here is my controller (dashboard.js):
(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] }
]
};
});
})();
My html file (index.html):
<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>
My app.js file:
'use strict';
/*
* Defining the Package
*/
var Module = require('meanio').Module;
var Dashboard = new Module('dashboard', ['zingchart-angularjs']);
/*
* All MEAN packages require registration
* Dependency injection is used to define required modules
*/
Dashboard.register(function(app, auth, database, circles) {
//We enable routing. By default the Package Object is passed to the routes
Dashboard.routes(app, auth, database, circles);
//We are adding a link to the main menu for all authenticated users
Dashboard.menus.add({
title: 'dashboard',
link: 'dashboard',
roles: ['authenticated'],
menu: 'main'
});
Dashboard.angularDependencies(['zingchart-angularjs']);
return Dashboard;
});
In case anyone else comes across this problem or one similar, I will post my answer.
Within the package/folder you want to add the zingchart dependency, or any dependency for that matter, you have to add it to your bower.json file like this.
{
"name": "packagename",
"version": "0.0.1",
"dependencies": {
"zingchart-angularjs": "latest" <!--dependency-->
}
}
then in your app.js file you need to register the zingchart dependency like this
'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;
});
you then need to make sure the zingchart dependency library is inlcuded in this path /public/assets/lib and make sure that this path is correctly referenced in your .bowerrc file like this
{
"directory": "public/assets/lib"
}
then you can proceed to add the code that creates and renders the actual chart in your controller.js file
(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] }
]
};
});
})();
and finally, you can reference this code in your html file like this
<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>