score:8
I believe that your problem is not padding, but I could be wrong. As I see it, your problem is the auto-detection of the height of the drawable area, when the maximum number in your data is nice and round, like 60 is. Try to see if the problem persists when the maximum number is 61, 62, etc. So, I suggest you cook your data, so that no such problems occur. If data-cooking is not an option, try to explicitly define the maximum tick in the y-axis, so that it is just a bit over the maximum number in the data. In your case, try using this:
yAxes: [{
display: false,
ticks: {
max: 62
}
}]
So you will need to calculate the maximum number in the data and add something small, in order to explicitly define a maximum tick that will get rid of the unexpected cropping. Someone could have a better understanding and solution but that is the option I can think of. That, and cooking your data, of course.
score:0
I've been investigated how to make a hotfix to solve that. I saw three strange behaviors:
1- The data breaks if have heavy changes, for example:
[0, 10, 70, 30, 20, 12, 50, 200, 200, 200, 200, 200]
2- The 'error' is always the half of the height of our borderWidth.
3- That error may was introduced when we changed the line 36 of core.layoutService.js on the next COMMIT
In second place I saw two strange padding vars inside the function 'update' of the core.layoutService:
Around the line 29 we have the function and on lines 35 and 36 we have the strange vars.
// The most important function
update: function(chartInstance, width, height) {
if (!chartInstance) {
return;
}
var xPadding = 0;
var yPadding = 0;
I have been seen what the function does with that vars, specially with yPadding. I couldn't se any useful calc done with yPadding. In my opinion here is the problem. We always maintain the yPadding to 0 and IMHO it was an error applied in another version of that file HERE .
The solution is that follows and I developed that because is the demand behind the developer of that commit deleted the line.
THAT'S A HOTFIX, I WILL MAKE A PR AND IF IT IS APPROVED IT WILL BE THE SOLUTION
If you apply that code you will can set your padding on the styles config of the chart, also, if you don't apply any config he will take a default based on the chart height.
Config prop example:
padding: {
x: 5,
y: 4
},
You have the code and all the explanation here: https://github.com/chartjs/Chart.js/pull/3349
score:4
If you want to increase the "buffer" on the Y axis so that the maximum value doesn't get displayed all the way to the top, I've successfully done it using "grace".
options: {
scales: {
y: {
type: 'linear',
grace: '10%'
}
}
}
score:19
If I understood the question correct, current version (>2.4) of Chart JS supports padding config option around chart layout.
layout: {
padding: {
// Any unspecified dimensions are assumed to be 0
top: 25
}
}
Source: stackoverflow.com
Related Query
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Converting Chart.js canvas chart to image using .toDataUrl() results in blank image
- Why is chart.js canvas not respecting the padding of the container element?
- Chart.js padding canvas
- set background color to save canvas chart
- chartjs - top and bottom padding of a chart area
- Can Chart.js combines Line Chart and Bar Chart in one canvas
- (Vue, ChartJS) Create gradient background for chart from child component canvas context
- Chart.js doughnut canvas padding
- Chart.js pie chart not showing in Google Chrome canvas
- Increase padding between legend and chart with react-chartjs-2
- ChartJS: Remove padding to the right of chart caused by tick labels
- React chart : prevent chart's canvas scaling with height and width
- Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. chat.JS
- canvas fill text vanishes when hovering over chartjs pie chart
- Chart js 2.x renders the canvas invisible
- Remove padding from chartJs horizontal bar chart
- I am using chartjs node canvas to render a chart however the graph options are being ignored
- Chart Js flickering or switching as i move mouse on canvas
- Create a chart on a dynamically created canvas in Angular-chart.js
- chart.js cuts off canvas - but padding makes doughnut very small
- How to clear/destroy Chart.js canvas when the chart is represented as a react JSX element
- Chart.js: get chart data from canvas
- Chart js, Canvas is null polymer project
- Chart.js canvas and chart width gets overwritten when redrawn
- How to load chart data to an appended canvas
- Unable to set width and height on canvas in chart js
- How to get the data attribute of the canvas chart created using chartjs
- Bug in canvas class in chart js
- Remove Chart.js chart padding
More Query from same tag
- How to Create Single line bubble Chartjs chart?
- Is it possible to have tick stepSize for each dataset in Chart.js?
- Deleting and recreating an element with React
- Group data from CSV (D3.js & Chart.js)
- chart.js Line chart with different background colors for each section
- My point annotation in Chart.js 3.3.2 won't render in my Django template. Making a realtime graph of temperature for my wood-fired pizza oven
- Can't bind to 'chartType' since it isn't a known property of 'canvas' with angular12
- How do you create an extension to Chart.js?
- Email a chartjs graph in laravel
- Manipulating data point in chart.js external tooltip
- Adding color dynamically to Chart.js
- ChartJS 2.9.4 can't overlay line data on Horizontal Bar chart
- Chartjs annotations-plugin: Can I add multiple vertical lines to identically named x-axis labels?
- Passing the same props while rendering different elements conditionally in React.js
- ChartJS: Grouped Stacked Bar Chart not Grouping
- Updating chart.js with array index 0 doesn't work
- Replace Chart.js Data during `onClick` causes _meta error
- Chart.js - access yAxes properties
- ChartJs Memory Leak | Garbage Collection does not clean Chart Object or Arrays after render
- Is it possible to revert x-axe values in line chart with chart.js
- Datalabels plugin throws error when using scriptable option
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- ChartJS, Disable Tooltip for one plot on a multi graph data
- How to add comma in this chart js
- Better looking function
- Mixed Diagram (Line/Bar) with two y-Axis won't display data on 2nd Axis
- Chart.JS: Stop chart from rescaling when hiding/unhiding a dataset?
- hh:mm in chart.js on X-axis and text labels on the Y-axis
- How can I make two of my lines in Chart JS thicker
- Chartjs - show elements in all datasets on hover using bar chart