score:1
i used this to add percentage to yaxis-
const options = {
showLines: true,
scales: {
yAxes: [
{
ticks: {
min: 0,
max: 100,
stepSize: 20,
callback: function (value) {
return (value / this.max * 100).toFixed(0) + '%'; // convert it to percentage
},
},
type: "linear",
display: true,
position: "left",
id: "y-axis-1",
gridLines: {
drawOnArea: false,
},
},
],
},
};
score:2
Of using the toLocaleString
function
scales: {
yAxes: [
{
ticks: {
callback: function (value) {
return value.toLocaleString('de-DE', {style:'percent'});
},
}
},
],
},
score:2
With Chart.js 3 you can do this:
const options = {
scales: {
y: {
ticks: {
format: {
style: 'percent'
}
}
}
}
};
score:5
Don't think there is a out of the box version of that yet. You might have to do it a bit manually by calculating the percentages before setting the chart up and e.g. follow this example to create the graph: https://stackoverflow.com/a/40438511/6638478
score:6
If you have a static total...say a max value of 800, you can just show custom ticks like this:
ticks: {
//.. Other settings
stepSize: 200, /* total/4 shows 0, 25%, 50%, 75%, 100% */
callback: function(value, index, values) {
return ((value / 800) * 100) + '%';
}
}
score:24
You could do something like this:
If you know the absolute value that represents 100% in your dataset, you can pass this to your options object:
scales: {
yAxes: [
{
ticks: {
min: 0,
max: this.max,// Your absolute max value
callback: function (value) {
return (value / this.max * 100).toFixed(0) + '%'; // convert it to percentage
},
},
scaleLabel: {
display: true,
labelString: 'Percentage',
},
},
],
},
Source: stackoverflow.com
Related Query
- Chart.js Bar graph with percentage values
- How to display inline values in a stacked bar chart with Chart.js?
- Display Bar chart values in the graph - ChartJS
- Bar chart with min height and zero values - ChartJs
- Stacked bar chart with chartjs with included values
- Hiding spaces with zero values in bar chart with chart.js
- Chart Js , loading data on selection but bar graph displaying old values as well on hovering
- hiding x-axes labels with 0 values on a bar chart
- How to change bar color on a angular-chart and chart js bar graph with multiple datasets?
- Horizontal stacked bar chart with chart.js
- line chart with {x, y} point data displays only 2 values
- Vertical stacked bar chart with chart.js
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js Mixed Bar and Line chart with different scales
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- Chart.js - Draw bar chart with multiple labels
- ChartJS bar chart with legend which corresponds to each bar
- angular-chart.js bar chart with 100% opacity color
- Chartjs - data format for bar chart with multi-level x-axes
- Fill Chart.js bar chart with diagonal stripes or other patterns
- Showing Percentage and Total In stacked Bar Chart of chart.js
- Create a rounded bar graph with Angular and chartJS
- Chart.js - Bar chart with linear cartesian (numerical) X axis?
- Is it possible to revert x-axe values in line chart with chart.js
- Chart.js with dual axis on bar and line graph
- Stacked horizontal bar chart along total count with chart.js
- Adding custom text to Bar Chart label values using Chart.js
- How to show data values in top of bar chart and line chart in chart.js 3
- Stacked bar chart with rounded corner of bar using Chart.js
- How to Create Chart.JS Bar Graph with Min, Max & Average
More Query from same tag
- Angular using PrimeNG charjs problem with font colors
- Inner Radius is not changed in Chart.js (Doughnut Chart)
- Chart.js jQuery dropdown selected values
- Horizontally align Chart.js y axes
- Can't pass array to chart.js which got its data from @Input
- Change section element every 20 seconds
- How to add dataset legend in chartjs tooltip
- Data will not draw onto my chart
- How can I get chart.js to automatically add colours for dynamic labels?
- White Space in stacked bar using chart.js
- Using Chart.js with Gatsby markdown
- How to replay animation chart.js
- Grouped Bar Char in D3.js or Google Charts or Chart.js
- Uncaught TypeError: Cannot read property 'format' of undefined
- Which is the appropriate lifecycle hook to draw a line?
- mysql sum query for chartjs
- Custom tooltip styling in Chart.js
- Chart.js page is zooming out everytime we change to a different graph while using a browser on with IOS El Capitan or latest iPad version
- ChartJS large data range
- How to make chartjs pie chart responsive
- Usage of ChartJS v3 with TypeScript and Webpack
- Chart JS tooltip and label width is zeroed
- How do I change the bar colors in chart.js barcharts?
- how can i reset chartjs object all instances and recreate it from scratch?
- How to remove strikethrough from label once click on legend
- How to add labels on top of the chart bar with Chart.js 2
- Why are the default Chart.js legend boxes transparent rectangles?
- Data Labels are getting cut off on the top
- JSON Data Assigning to Javascript Var Value
- Uncaught ReferenceError: Chart is not defined - Chart.js in laravel 5