-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gauge will not become responsive #73
Comments
I have the same problem: is there any solution?? thankyou... |
Yes, i found a solution: Add style width 100%
Remove the "style" attribute after you render the control:
It's a little bit hack |
This way it becomes very ugly |
you can suggered any solution then? greetings. |
Sorry for my short answer, yes I will. But I'm still struggling how. My problem is it gets pixelated. I was trying to ask the same question on Stackoverflow but they so often waste time by telling people they ask wrong. But I take your punch back as a fair one, my comment was too short. I will when I have something. |
no problem my friend, I'd searched anywhere without success. you are skype account? for chat and show you how It worked. Maybe we can get any solution together. Grettings |
I have managed to make it 100% responsive now, only with a little bit of lag allowing it to be redrawn. My solution is made in Vue.js, but I will try to explain it without Vue. I hope this can help you :-) The conceptEvery time the screen resizes the canvas needs to be redrawn and sizes must be set as HTML attributes for it to be drawn properly. This solution dont' take into account if you resize elements with Javascript, in that case you need to redraw it manually. The codeI have not refactored my code here, so it's a bit dirty: put the canvas into a div <div id="gaugeContainer">
<canvas id="gauge"></canvas>
</div> Have a function to draw it function draw() {
var width = document.getElementById('gaugeContainer').offsetWidth;
var height = width / 2;
document.getElementById('gauge').setAttribute('width', width +'px');
document.getElementById('gauge').setAttribute('height', height +'px');
var options = {};
var gauge = new Gauge(document.getElementById('gauge')).setOptions(options);
document.getElementById('gauge').maxValue = 100;
document.getElementById('gauge').set(60);
} And a function to redraw it var timeoutHandle = null;
function redraw() {
document.getElementById('gauge').getContext('2d').save();
document.getElementById('gauge').getContext('2d').setTransform(1, 0, 0, 1, 0, 0);
document.getElementById('gauge').getContext('2d').clearRect(0, 0, document.getElementById('gauge').getContext('2d').canvas.width, document.getElementById('gauge').getContext('2d').canvas.height);
document.getElementById('gauge').getContext('2d').restore();
if (timeoutHandle)
window.clearTimeout(timeoutHandle);
timeoutHandle = window.setTimeout(draw, 250);
} On page load, make sure to draw it and add an event listener for window resize. draw();
window.addEventListener('resize', redraw); Finally have this CSS that prevents it from messing up your grid system canvas {
max-width: 100%;
} |
hi, thank you |
Hey guys, Just a suggestion/fix, which works for me without any additional coding: canvas#da-gauge { |
@adadgio 's answer works for me! |
Thanks @adadgio |
I have a question, Are you not filling the HTML page with a lot of Gauges everytime you resize the window instead of destroying first and create it again? |
thanks @adadgio it fixed the issue for me |
The gauge becomes blurry when the canvas element is scaled with CSS. Is there a better alternative? |
Hi, I am having a little issue, with the gauge not wanting to be responsive, I am using Bootstrap and I have add the following to the CSS
canvas {
width: 100%;
height: auto;
}
and also this to the JS part
scaleOverride : true,
Now I don't know if your script support this function, but what happens is that the gauge completely gets removed from the page.
If you can help that be great
The text was updated successfully, but these errors were encountered: