Show Tooltip Labels On angular-chart Bar Chart
Adding the following works for pie charts and such, but NOT for bar charts.
$scope.options = {
tooltipEvents: [],
tooltipCaretSize: 0,
showTooltips: true,
onAnimationComplete: function() {
this.showTooltip(this.segments, true);
}
}
This is really odd and I am wondering if it is due to how the bar chart data is defined (as an array of array, e.g. [ [2,3,4], [5,6,7] ] with each inner array being the data for a single data series).
I am only using a single series bar chart, e.g. [ [2, 3, 4] ], and it renders nicely. However, I am not able to get the tooltip labels permanently (not just on hover).
Help please, :(
See fiddle: http://jsfiddle.net/g0vg14ww/2/
I want to show the tooltip on barchart so can you help me. i have tried the same code but it's not working for barchart. please help me $scope.options = { tooltipEvents: [], tooltipCaretSize: 0, showTooltips: true, onAnimationComplete: function() { this.showTooltip(this.segments, true); } }
Hi all,
Did anyone got the tooltips on bar chart?
For anyone is trying to handle the event: onAnimationComplete Notice the options structure should be:
"options" : {
"animation" : {
"onComplete" : function () {
...
}
}
}
For anyone who still needs help, I am sorry for the lack of response till date.
I did manage to figure it out on my own previously, which was why I closed the issue.
Here, ...
If you wish for the tooltips to be shown permanently, and not just on mouse hover, in the barChart.controller.js, this is what you set as the options:
$scope.barChartOptions = {
showToolTips: true,
tooltipEvents: [],
onAnimationComplete: function() {
this.showTootip(this.datasets[0].bars,true);
}
};
If you wish for the tooltips to be shown only on mouse hover, in the barChart.controller.js, this is what you set as the options:
$scope.barChartOptions = {
showToolTips: false,
tooltipEvents: ["mousemove", "touchstart", "touchmove"],
};
For both options, in the relevant barChart.view.html, this is what you have:
<canvas chart-data="$scope.barChartData"
chart-labels="$scope.barChartLabels"
chart-options="$scope.barChartOptions"
class="chart chart-bar">
</canvas>
Thanks
On Wed, Aug 24, 2016 at 1:48 AM, R4ZuL [email protected] wrote:
I tried to show the tooltips permanently for a pie chart but the following code did not work:
// pieChart.controller.js class PieChartController { constructor() { var self = this; self.labels = ['Download Sales', 'In-Store Sales', 'Mail-Order Sales']; self.data = [300, 500, 100]; self.options = { tooltipEvents: [], tooltipCaretSize: 0, showTooltips: true, onAnimationComplete: function() { self.showTooltip(self.segments, true); } } } }
export default PieChartController;
//pieChart.component.js import template from './pieChart.tmpl.html'; import controller from './pieChart.controller.js';
let pieChartComponent = { scope: {}, template, controller };
export default pieChartComponent;
// pieChart.tmpl.html
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jtblin/angular-chart.js/issues/337#issuecomment-241863408, or mute the thread https://github.com/notifications/unsubscribe-auth/ALdW_BY9LJ3f7UaU17KJHCVGkxDaVhTeks5qi1WvgaJpZM4Hwrfw .
I tried the code below: $scope.barChartOptions = { showToolTips: true, tooltipEvents: [], animation: { onComplete: function() { console.log('onComplete event'); this.showTooltip(this.segments, true); //this.showToolTips(this.datasets[0].bars,true); } } };
and the result is this: onComplete event app.js:41 Uncaught TypeError: this.showTooltip is not a functiononComplete @ app.js:41startDigest @ Chart.min.js:11(anonymous function) @ Chart.min.js:11
Please take note that it is
onAnimationComplete: function() {
and not
animation: {
onComplete: function() {
Also, if you could just kindly format your code nicely in the future with indentation, that would make it a lot easier for others to read your comment, thank you!
I have switched to the code below, but it didn't work:
$scope.options = {
showToolTips: true,
tooltipEvents: [],
onAnimationComplete: function() {
alert('animation');
this.showTootip(this.datasets[0].bars,true);
}
};
I have created the following fiddle: https://jsfiddle.net/kekonen/ejg1jh9n/
That's because you are using the latest versions.
I was not. I was using:
"angular-chart.js": "~0.8.8",
"chart.js": "^1.0.2",
You may wish to check out the latest configuration options at : http://www.chartjs.org/docs/#chart-configuration-tooltip-configuration
Ok. Just for doubt avoidance... do you mean that it works in previous versions but not on latests?
Well, it worked in my project, which I have not updated in some time; hence why the versions used are so old.
On Oct 18, 2016 7:37 PM, "erikneto" [email protected] wrote:
Ok. Just for doubt avoidance... do you mean that it works in previous versions but not on latests?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/jtblin/angular-chart.js/issues/337#issuecomment-254482222, or mute the thread https://github.com/notifications/unsubscribe-auth/AFBrTrx4fHfCWEvpL9YH43XaWZC7y_jxks5q1K9_gaJpZM4Hwrfw .
I see. I will give it a try later. Just confused if this functionality was intentionally removed or if it is a bug.
Thanks.
Chart.js had a lot of breaking changes going to 2.x so it is possible that it was deliberate, you should check Chart.js docs.
does anybody know a solution how to show values on a top of bar chart? since I'm using chartjs 2 code below doesn't work((( $scope.options = { showToolTips: true, tooltipEvents: [], onAnimationComplete: function() { alert('animation'); this.showTootip(this.datasets[0].bars,true); } };
That did hep me
$scope.options = {
events: false,
tooltips: {
enabled: false
},
hover: {
animationDuration: 0
},
animation: {
duration: 1,
onComplete: function () {
var chartInstance = this.chart,
ctx = chartInstance.ctx;
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function (dataset, i) {
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function (bar, index) {
var data = dataset.data[index];
ctx.fillText(data, bar._model.x, bar._model.y - 5);
});
});
}
}
};