score:5
Accepted answer
The easiest solution is to add padding to the top of your chart (simple sample below). You may also play around with the datalabel plugin's clamping options to adjust the position of the label when it's outside the chart.
const layoutOptions = {
padding: {
top: 30 // Add 30 pixels of padding to top of chart.
}
};
const data = {
labels: ['Large', 'Small'],
datasets: [{ data: [100, 2] }]
};
const config = {
type: 'bar',
data: data,
options: {
layout: layoutOptions,
scales: { y: { beginAtZero: true, max: 100 } },
plugins: {
legend: { display: false },
datalabels: { anchor: 'end', align: 'top' }
}
},
};
new Chart(document.getElementById('myChart'), config);
#myChart {
max-height: 180px;
}
<div>
<canvas id="myChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
<script>Chart.register(ChartDataLabels);</script>
Source: stackoverflow.com
Related Query
- How do I fix over limit y axis value in ChartJS
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How to set min Value a step down of min value received from database in Y Axis in ChartJS
- How to set max and min value for Y axis
- How to set ChartJS Y axis title?
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to change the cursor to a pointer when I hover over a bar in a ChartJS bar chart?
- chartjs - Drawing vertical line on integer x axis value
- Map event position to y axis value in chartjs line chart
- How do I make line charts overlay over bar charts in chartjs
- Chartjs change horizontal axis value
- How to add ChartJS code in Html2Pdf to view image
- How to remove bars for those bars with zero value in Chartjs bar chart?
- How to set lower limit for the highest value being displayed on Y Axis?
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- How to draw multiple line on y axis for same x axis in chartjs v2?
- How to set the chartjs bar graph scale to the highest value in the result data
- How to set y axis to the max dataset value in Chartjs?
- How to draw a range label on x axis using chartJS
- How to set ChartJS Axis label with PrimeFaces
- How to show tooltip value of all data falling on the same axis in chart js?
- how to disable last/max value shown on x axis in chart js?
- how to display last x float number value in chartjs
- ChartJs - Labelling minimum and maximum value of the Y Axis
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- how to show bar value on the top of each bar in chartjs
- How to sum the array value in javascript like chartjs data array and input value sum
More Query from same tag
- ChartJS align bars to left instead of center
- Changing width and height in angular-chart.js module
- How to assign different background colors to chart.js pie chart data set?
- How to add a Date Selector to Chartjs in the context of Vue.js
- ChartJs how can I move bar into new group?
- How to change cursor on hover of data labels in chart.js version 3?
- How do I create stacked chart with Chart.js version 2.0.0-beta
- ChartJS How to set max labels for X axis?
- Completely hide empty bars in chart.js
- Chartjs does not show on pdf in yii2 despite showing in html view
- Two chartjs charts on page throwing data undefined error
- Bollinger bands in React application with a library
- Line chart Change background color of shaded region on hover (Chartjs)
- Single bar with background Chart.js
- Display data labels on a pie chart in angular-chart.js
- Blazor ChartJs: Expanding bar to the end of the canvas
- Chartjs: Why do I have 2 Y Axis labels?
- Chart.js with handlebar.js shows empty canvas
- Script error : "Uncaught SyntaxError: Unexpected identifier"
- dynamically update Chart.js draw line chart dataset data
- How to set ChartJS Y axis title?
- Is there a way to change part of the title to another font style or set a custom title format in Chart.js?
- Accessing data from the callback function of a bar chart using chart js
- how to display chart.js legend with different bar color
- Using two JSON objects to make Chart.JS Bar Chart Dynamic in Typescript / Angular
- Resizing a Chart.js chart
- Should I remove the leading "0" when sending PHP array to JSON?
- Vertical align bar chart from chart.js not working
- Chart.js, adding footer to chart
- ChartJs custom tooltip position