Chart.js canvas resize
I had a lot of problems with that, because after all of that my line graphic looked terrible when mouse hovering and I found a simpler way to do it, hope it will help :)
Use these Chart.js options:
// Boolean - whether or not the chart should be responsive and resize when the browser does.
responsive: true,
// Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
maintainAspectRatio: false,
React chart : prevent chart's canvas scaling with height and width
In my case, settingmaintainAspectRatio:false
along with supplying height/width on div
<div style={{height:'100px',width:'200px'}}>
<HorizontalBar data={data} options={chartOptions}/>
</div>
helped in restricting the canvas's scalability.
Relevant Source: https://www.chartjs.org/docs/latest/general/responsive.html#important-note
Set height of chart in Chart.js
Seems like var ctx = $('#myChart');
is returning a list of elements. You would need to reference the first by using ctx[0]
.
Also height is a property, not a function.
I did it this way in my code:
var chartEl = document.getElementById("myChart");
chartEl.height = 500;
charts.js chart size it's diferente than container setted size
try to add 2 properties to options object:
responsive: true,
maintainAspectRatio: false
Chart.js unwanted canvas resizing
Presumably the option you need is devicePixelRatio
, which will:
Override the window's default devicePixelRatio.
I've not tested it, and the documentation isn't 100% clear, but I assume this goes in the root of the options
object:
options: {
devicePixelRatio: 1
}
Related Topics
Replace Multiple Strings With Multiple Other Strings
Discord Bot Not Getting All Users
Ng2-Smart-Table Bind 'Add New' Button Event to an External Button
Android Webview Not Loading Website Properly
Counting Records in Json Array Using JavaScript and Postman
React Js - Uncaught Typeerror: This.Props.Data.Map Is Not a Function
Prevent Html5 Videos from Downloading the Files on Mobile - Videojs
Make the Bootstrap Table Scroll-Able Vertically and Horizontally With Fixed Header
Convert Jquery Code to JavaScript
How to Check a Postal Code in JavaScript
How to Make an Empty String Array in Typescript
Calculate Distance Between Two Moving Elements
How to Format a Float as Integer When .Tofixed(2) Gives Zeros After the Decimal Point
Comparing Two Json Arrays and Get Not Matching Values
How to Change Div Order in JavaScript
Resize a Base-64 Image in JavaScript Without Using Canvas
How to Change Image Source on Hover Using Javascript, But Applies to Each Individual Photo