我试图显示图表的信息,而无需用户将鼠标悬停在图表的任何部分。我将 Chart.js 与 Angular.js 一起使用
我的疑问与此question here!
相同html 代码:
<div class="wrapper-chart" >
<canvas
id="pie"
class="chart chart-pie"
chart-data="data"
chart-labels="labels"
chart-options="options"
chart-colors="colors"
legend = "true"
chart-series="series">
</canvas>
</div>
angular 代码:
angular
.module('myBeeApp.controllers')
.controller('chartHome', chartHome);
chartHome.$inject = [
'$scope'
];
function chartHome(
$scope
){
$scope.labels = ["Primavera", "Verão", "Outono", "Inverno"];
$scope.data = [32, 53, 14, 79];
$scope.options = {
showToolTips: true,
tooltipEvents: [],
onAnimationComplete: function() {
this.showTootip(this.datasets[0].bars,true);
},
title: {
display: true,
text: 'Quantidade por Estação',
fontColor: '#ff8c1b',
fontFamily: 'HelveticaNeue',
fontSize: 26,
},
legend: {
display: true
},
cutoutPercentage: 50,
};
$scope.colors = ["#FF7400", "#C85B00", "#FFB77B", "#E3831E"];
}
图表生成正确,但没有信息显示。
生成的图表(我的图表):
我是多么喜欢它(有标签):
我已经尝试过这段代码,但没有为我工作!
$scope.options = {
tooltipEvents: [],
showTooltips: true,
tooltipCaretSize: 0,
onAnimationComplete: function () {
this.showTooltip(this.segments, true);
},
};
我还试过following these steps!根本没有工作!(这就是为什么我认为它不是一个重复的问题 )
版本:angular - v1.6.6;角图 - v1.1.1; chart.js - v2.7.1
感谢您的一切!
答案 0 :(得分:1)
我跟着你提到的Post。我更改了图表类型,标签,颜色和数据。它显示图表中的标签,无需根据需要悬停
angular.module('App', ["chart.js"]);
angular.module('App').controller('Controller', ['$scope', '$http', '$location', '$window',
function($scope, $http, $location, $window) {
$scope.options = {
tooltipEvents: [],
showTooltips: true,
tooltipCaretSize: 0,
onAnimationComplete: function() {
this.showTooltip(this.segments, true);
},
};
var diskDataJson = {
"data": [32, 53, 14, 79],
"labels": ["Primavera", "Verão", "Outono", "Inverno"],
"colours": ["#FF7400", "#C85B00", "#FFB77B", "#E3831E"]
};
$scope.pieDiskData = diskDataJson;
}
]);
&#13;
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js"></script>
<script type="text/javascript" src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/jtblin/angular-chart.js/0.8.0/dist/angular-chart.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/jtblin/angular-chart.js/0.8.0/dist/angular-chart.css">
<div ng-app="App">
<div ng-controller="Controller">
<canvas id="pie33" chart-options="options" class="chart chart-doughnut chart-xs ng-isolate-scope" height="120" width="240" chart-data="pieDiskData.data" chart-labels="pieDiskData.labels" chart-colours="pieDiskData.colours" chart-legend="true"></canvas>
</div>
</div>
&#13;
Fiddle演示