score:2
Accepted answer
I solved it. by passing an array to the label in data. And rest of the code is as below.
function productChart() {
var data = {
labels: productHistoryDates,
datasets: [{
label: productHistoryProducts1.name,
data: productHistoryProducts1.quantity,
backgroundColor: "#26B99A"
},
{
label: productHistoryProducts2.name,
data: productHistoryProducts2.quantity,
backgroundColor: "#03586A",
},
{
label: productHistoryProducts3.name,
data: productHistoryProducts3.quantity,
backgroundColor: "#03226A",
}]
};
var ctx = document.getElementById("productChart").getContext("2d");
var myBarChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
label: function (tooltipItems, data) {
var tooltip = data.datasets[tooltipItems.datasetIndex].label[tooltipItems.index];
return tooltip;
}
}
},
scales: {
yAxes: [{
gridLines: {
display: true
}
}],
xAxes: [{
gridLines: {
display: true
},
ticks: { mirror: true },
barPercentage: 0.8
}]
}
}
});
}
Source: stackoverflow.com
Related Query
- How to show different product name for every bar in chart js
- how to show bar chart for every product
- PrimeNg bar chart how to show a label for the y-axis
- How do I get a different label for each bar in a bar chart in ChartJS?
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Different color for each column in angular-chartjs bar chart
- How to show Y axis ticks for every point in the graph
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to show thousand in k format for bar values in chart.js
- How to show data values in top of bar chart and line chart in chart.js 3
- Angular chart how to show the legend data value by default along with legend name
- Vue ChartKick - different colours for bar chart
- How to show gradient vertically on chart js grouped bar chart?
- How to map json array to two different array for chart
- How to retain spacing between bars for two different bar charts in Chart.js 2
- angular-chart.js : how to show numbers in each bar of stacked bar chart
- Chart.js: How to get x-axis labels to show on top of bars in bar chart
- How to use set the color for each bar in a bar chart using chartjs?
- How can I have different values for the chart and the tooltip in chart.js?
- How to draw baseline for bar chart in chart.js
- Horizontal gradient for every single bar in group chart js
- Charts.js - Bar chart different colors for value intervals not working
- How to set X coordinate for each bar with react chart js 2?
- How to show the chartjs bar chart data values labels as text?
- Chartjs : Can I overwrite bar value on hover for every bar chart
- how can i show labels and value in both on bar chart
- How can I set different colours for each bar in angular-chart.js v1.0.0?
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How to change the position of the tooltip for the Bar type chart in Chart.Js
More Query from same tag
- how to use chart.js in webpacker rails 6
- Adapting a JavaScript code to be dynamic
- Chartjs Bar Chart add background color to value labels
- How to add a Date Selector to Chartjs in the context of Vue.js
- angular-chartJs change chart background and highlight colors
- Chartjs-node installation failing
- ChartJS multiple annotations (vertical lines)
- Chartjs doesn't update dataset label on tooltips
- Chart.js tooltip background color setting
- chart.js - Horizontal lines per bar
- Loading data into chart on html page
- Resizing a Chart.js chart
- Trying to create a custom tooltip in a doughnut chart using chartsjs, but it is not working
- How to draw a line in line chart for single value in Charts.JS
- React-chartjs-2 update height dynamically
- Type 'import("/@types/chart.js/index.d.ts")' is missing the following properties from type 'any[]': length, pop, push, concat, and 26 more
- How to add axis titles in chart.js charts
- Make Chart.js Radar labels clickable
- Time format on the x axis in Chart.js
- How do I use plugins in ng2-charts?
- 2 or more charts on same page?
- Chart.js 2.1.6 background color for each section
- i have an error when use chart on laravel
- Stacked areachart with percents values on the y axis using Charts.js and Angular 8
- How to implement mysql database connection in Chart.js
- Not able to remove legent from Radar Chart in chart.js even using legent: {display : false}
- Chart JS: Always show tooltips in a multi dataset line chart
- Chart.js not rendering chart with data from mySQL database
- Syntax Error: Token '{' invalid key at column 2 of the expression [{{id}}] starting at [{id}}]?
- Angular 2 ng2-charts donut add horizontal line