【发布时间】:2017-02-24 23:52:51
【问题描述】:
我一直在开发一个使用图表 JS 的移动应用程序。我被困在一个需要通过单击图标来绘制图表的地方。
问题是,图标在template1.html,图表应该在template2.html绘制。我正在使用 angularJS。因此,每个图表都有其控制器。
因此,图表的所有代码都在 template2Controller 中。问题来了,如何通过单击 template1.html 处的图标在 template2.html 处绘制图表。
template1.html
<button class="" ng-click="daily()">
</button>
template2.html
<div id="dailyTab" class="chart" >
<canvas id="dailyChart" ></canvas>
</div>
template2Controller
$scope.daily = function() {
$http.get('jsonAPIURL'
).success(function(response) {
var dailyCoffee = [];
angular.forEach(response, function(value, key) {
dailyCoffee.push(value.Currency);
});
var daily = {
labels: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'],
datasets: [{
backgroundColor: "rgb(3,191,179)",
data: dailyCoffee
}]
};
var ctx = document.getElementById('dailyChart').getContext('2d');
var chartDaily = new Chart(ctx, {
type: 'bar',
data: daily,
options: {
responsive: true
}
});
});
};
【问题讨论】:
标签: javascript html angularjs ionic-framework chart.js