admin管理员组文章数量:1302329
I'm trying to use the angular-chartjs library but running into some issues. There are no errors on the page. But the canvas is empty.
Anyone has an idea? I've tried reordering the scripts a few times. I just can't figure it out. :(
Here is the html.
<html ng-app="profitly">
<head>
<script src="js/lib/jquery.min.js"></script>
<script src="js/lib/Chart.js"></script>
<script src="js/lib/angular.min.js"></script>
<script src="js/lib/angular-route.min.js"></script>
<script src="js/lib/angular-chartjs.min.js"></script>
<script src="js/controller.js"></script>
</head>
<body ng-controller="MainController" class="container-fluid">
<div class="wrapper" ng-view>
<article ng-controller="graph">
<cjs-doughnut dataset="someData" options="someOptions" segment-stroke-width="5"></cjs-doughnut>
</article>
</div>
</body>
<html>
And here is the app initialization:
var app = angular.module('profitly', ['ngRoute', 'chartjs']);
And here is the controller for this part:
app.controller('graph', function($scope) {
$scope.someData = {
labels: [
'Supply',
'May',
'Jun'
],
datasets: [
{
data: [1, 7, 15, 19, 31, 40]
},
{
data: [6, 12, 18, 24, 30, 36]
}
]
};
$scope.someOptions = {
segmentStrokeWidth: 20,
segmentStrokeColor: '#000'
};
});
I'm trying to use the angular-chartjs library but running into some issues. There are no errors on the page. But the canvas is empty.
Anyone has an idea? I've tried reordering the scripts a few times. I just can't figure it out. :(
Here is the html.
<html ng-app="profitly">
<head>
<script src="js/lib/jquery.min.js"></script>
<script src="js/lib/Chart.js"></script>
<script src="js/lib/angular.min.js"></script>
<script src="js/lib/angular-route.min.js"></script>
<script src="js/lib/angular-chartjs.min.js"></script>
<script src="js/controller.js"></script>
</head>
<body ng-controller="MainController" class="container-fluid">
<div class="wrapper" ng-view>
<article ng-controller="graph">
<cjs-doughnut dataset="someData" options="someOptions" segment-stroke-width="5"></cjs-doughnut>
</article>
</div>
</body>
<html>
And here is the app initialization:
var app = angular.module('profitly', ['ngRoute', 'chartjs']);
And here is the controller for this part:
app.controller('graph', function($scope) {
$scope.someData = {
labels: [
'Supply',
'May',
'Jun'
],
datasets: [
{
data: [1, 7, 15, 19, 31, 40]
},
{
data: [6, 12, 18, 24, 30, 36]
}
]
};
$scope.someOptions = {
segmentStrokeWidth: 20,
segmentStrokeColor: '#000'
};
});
Share
edited Sep 14, 2014 at 0:59
Imalea
asked Sep 14, 2014 at 0:32
ImaleaImalea
3765 silver badges14 bronze badges
2 Answers
Reset to default 5Someone else on my hack team figured it out later that day. Here is the HTML:
<article class="col-xs-6 col-md-offset-3 col-md-6 center">
<canvas id="expenses" width="200" height="100"></canvas>
<script>
var pieData = [
{
value: 20,
color:"#878BB6"
},
{
value : 40,
color : "#4ACAB4"
},
{
value : 10,
color : "#FF8153"
},
{
value : 30,
color : "#FFEA88"
}
];
var pieOptions = {
segmentShowStroke : false,
animateScale : true
}
var expenses = document.getElementById("expenses").getContext("2d");
new Chart(expenses).Pie(pieData, pieOptions);
</script>
</article>
For more, our github repo (the view was the "cashflow.html" one) and to see how it rendered.
Probably not the best way to do it.
It looks like your missing ng-app
in your HTML
which would contain which angular app you will be using.
You can put it in the inside one of the divs
wrapping the graph.
本文标签: javascriptChartJS with AngularJSCanvas won39t display anythingStack Overflow
版权声明:本文标题:javascript - ChartJS with AngularJS - Canvas won't display anything - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741714430a2394024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论