我目前在我的应用程序中使用角度图表。我创建了一个完美运行的折线图,但是当添加第二个图表(饼图)时,第一个图表不会显示在前端,直到我将鼠标悬停在它上面或调整窗口大小。
我没有设置悬停事件,所以我不确定为什么会这样。
这是我的控制器
app.controller('dashboardController', ['$scope', '$http', 'Page', 'authenticationService', function ($scope, $http, Page, authenticationService) {
// Page Setup
Page.setTitle('Dashboard');
Page.setSubTitle('Transport Overview');
$scope.$emit('pageLoading');
$http({
url: '/api/dashboard/',
method: 'GET',
headers: authenticationService.getAuthToken(),
}).success(function (data) {
$scope.dashboard = data;
$scope.dashboard.revenuePerDayLabels = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
$scope.dashboard.weeklyJobIncome = [data.weeklyJobIncome];
$scope.dashboard.weekVehicleRevenueLabels = [];
$scope.dashboard.weekVehicleRevenueData = [];
angular.forEach($scope.dashboard.weekVehicleRevenue, function (item) {
$scope.dashboard.weekVehicleRevenueLabels.push(item.registrationNumber);
$scope.dashboard.weekVehicleRevenueData.push(item.vehicleRevenue);
});
$scope.$emit('pageLoaded');
}).error(function () {
$scope.$emit('pageLoaded');
});
}]);
以及对应的HTML
折线图
<canvas id="line" class="chart chart-line"
chart-data="dashboard.weeklyJobIncome"
chart-labels="dashboard.revenuePerDayLabels"
chart-series="series">
</canvas>
饼形图
<canvas id="doughnut" class="chart chart-pie"
chart-data="dashboard.weekVehicleRevenueData"
chart-labels="dashboard.weekVehicleRevenueLabels">
</canvas>