score:4
Accepted answer
This could be solved by adding the options
onAnimationComplete
and tooltipevents
.
onAnitmationComplete
functions calls the showToolTip
method to show the tooltips
like a hover event does.
Usually tooltipevents
are define to show tooltips
but here an empty array need to be passed. Check the below fiddle example for line chart.
var options = {
tooltipTemplate: "<%= value %>",
showTooltips: true,
onAnimationComplete: function() {
this.showTooltip(this.datasets[0].points, true);
},
tooltipEvents: []
}
Note : This approach does not support multi data-sets in line and bar charts, but does support multi data-sets in pie charts
var data_line = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
}]
};
var options = {
tooltipTemplate: "<%= value %>",
showTooltips: true,
onAnimationComplete: function() {
this.showTooltip(this.datasets[0].points, true);
},
tooltipEvents: []
}
var context = $('#chart3').get(0).getContext('2d');
var chart = new Chart(context).Line(data_line, options);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<div id="chartContainer">
<canvas id="chart3" width="500" height="500"></canvas>
</div>
score:0
options: {
legend: {
display: false
},
hover: {
animationDuration: 0
},
animation: {
onComplete: function() {
const chartInstance = this.chart,
ctx = chartInstance.ctx;
ctx.font = Chart.helpers.fontString(
18,
Chart.defaults.global.defaultFontStyle,
Chart.defaults.global.defaultFontFamily
);
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
this.data.datasets.forEach(function(dataset, i) {
const meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function(bar, index) {
const data = dataset.data[index];
ctx.fillStyle = "#000";
ctx.fillText(data, bar._model.x, bar._model.y - 2);
});
});
}
},
tooltips: {
enabled: true
},
responsive: true,
scales: {
xAxes: [
{
display: true,
gridLines: {
drawOnChartArea: false
}
}
],
yAxes: [
{
display: true,
gridLines: {
drawOnChartArea: false
},
ticks: {
precision: 0
}
}
]
}
}
Source: stackoverflow.com
Related Query
- how to always show label in chartjs without mouseover?
- How to always show a label in ChartJS in React
- Chart.js - How To Show Value of Label as Percent of X and Y Values - Currently Always 100%
- Chartjs how to show scale label horizontally
- How to show label at right side of Y axis same as left side of Y Axis ChartJS
- ChartJS : How to leave just points without lines
- show label in tooltip but not in x axis for chartjs line chart
- ChartJS – How to show border on empty pie chart?
- How to add label for ChartJs Legend
- How to show data values or index labels in ChartJs (Latest Version)
- PrimeNg bar chart how to show a label for the y-axis
- How to get onClick Event for a Label in ChartJS and React?
- How to show tooltips always on Chart.js 2
- How to add ChartJS code in Html2Pdf to view image
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- how to show data label on barchart using chart.js in Angular10 project?
- How to make chartJs stacked bar always rounded when data is 0?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- ChartJS - How to increase the maximum degree of label rotation on x-axis?
- how to show labels in laravel charts when the name of the label is on another table?
- How to show both overlapping lines in in chartjs
- how to put a y-axis and x-axis label while using html and chartjs
- Always show last tooltip on all datasets, leave the rest to display on hover? ChartJS
- How to show a "total" sum label on the top of stacked bars
- ChartJS 3.x How to place tick label inside graph?
- In ChartJS how do I change the color of a label in the legend?
- How can I show chartjs datalabels only last bar?
- How to draw a range label on x axis using chartJS
- How to set ChartJS Axis label with PrimeFaces
More Query from same tag
- ChartJs custom tooltip position
- how to show X and Y labels on points in Chart js 2 Line Chart
- How to change background color in ng2-charts
- How to Draw Gantt chart using chart js or other libraries
- Time graphs chart.js
- Charts.js polar area scales
- how to filter year from datefield in django
- How to import and use a custom Chart.js plugin in Nuxt? (Chartjs-vuejs v2.9.4)
- How to create a charjs bar graph with many bars?
- Angular canvas is undefined
- In chart.js, how to know if a yAxes tick is bumping/rendering over/into another
- Chart.js how to change width of color
- Export HTML content with Chart.jscanvases to PDF
- Inverting X axis number labels in chart.js scatter chart
- How to rotate custom marker in chart.js?
- Chart JS, backgroundColor not showing
- Chartjs xaxis labels auto decrease disabled
- Add Space Between Bars in Angularjs Chartjs
- How to show data values in top of bar chart and line chart in chart.js 3
- Charts.js Dynamic Ticks
- React js Unhandled Rejection (TypeError): t[l].data.map is not a function
- How to filter data for dxChart
- Can't load multiple charts onto a page when looping through dummy array
- Force display of ticks on xAxes using chartkick gem and chart.js
- How can i loop some specific key in each index json data and put it in dataset: data ? (chart.js)
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- Can't parse data from json
- Chart.js / Google Charts and JSON
- Chart js bar with the highest value is a different color among the rest - React
- Cursor pointer change onhover not working in chartjsv3