Responsive sizing with lazy_high_charts gem? - ruby-on-rails

It is possible for highcharts to perform responsively, as seen in this fiddle.
It seems that lazy_high_charts defaults to width: 600px; height: 400px; when no width or height is supplied. Is there a workaround?

set height only will do the trick
LazyHighCharts::HighChart.new('graph', :style=>"height:260px")
if you preferer you can set width with percentages

Related

Make Select2 wider than the input?

I have various Select2 dropdowns. I have a issues where when the input is narrow and the drop down is also very small and hard to read.
I have tired:
.select2-dropdown.select2-dropdown--below {
min-width: 300px !important;
}
Which works great:
I am wondering if there is a way to have Select2 automatically adjust the width?
I figured this out as I was drafting the question - Its a combo of CSS and Select2 configuration:
Select2:
width: 'auto'
dropdownAutoWidth : true
CSS:
.select2-results__option {
white-space: nowrap;
}
.select2.select2-container {
width: 100% !important;
}
The nowrap was the key. That forces the option to be full width and then the Select2 config. My added 100% width was to keep the actual input select full width in the table I have these nested in.

How to fit an image without deforming his resolution?

I need to fit a vertical image in a horizontal frame without deforming the image and filling the rest with white.Im using paperclip.
I believe that's not a rails question, but a style (css) matter. Try to put some css like:
.img-paperclip{
width: 100%;
height: auto;
}
and, in your html element, something like:
<img src="..." class="img-paperclip" ...>
Hope it helps.

How can I reduce the width of a form check box?

I have a form, ending with an "I agree to these terms and conditions line" with a checkbox.
The code that I have for the checkbox is currently:
Although all is functioning well, the width of the checkbox element is too much. This causes a very wide space between the "I agree..." statement, and the actual checkbox. Any tips on how I can left align the checkbox, or reduce the width of the checkbox's element.enter image description here
Standard checkboxes in Rails could be changed with CSS in the following way:
input[type="checkbox"]
width: 10px //or however wide you desire
height: 10px
Although you should be detailed with your selector in case your checkbox is wrapped in some div with an ID, in which case the above will look slightly different:
#div input[type="checkbox"]
width: 10px //or however wide you desire
height: 10px

Highchart Solid Gauge Responsive

I created Solid Gauge chart using Highchart.
but when screen resolution changed chart is still displayed with original size.
i need responsive Solid Gauge chart.
Demo Link
The solid gauge chart handles size changes quite well by itself. I've updated the demo JFiddle to show how the gauge can handle resizing.
The main idea here is that when the window is resized, the width of the div is changed by CSS:
<div id="container-speed" style="width: 50%; float: left"></div>
And the height of the div is changed by JS:
function setDivHeight() {
var div = $('#container-speed');
div.height(div.width() * 0.75);
div = $('#container-rpm');
div.height(div.width() * 0.75);
}
$(window).on('load resize', function(){
setDivHeight();
});
Note that the ratio between width and height for the gauge seems to be ideal at 4:3, which is why the code multiplies by 0.75 to set the height.
Managing the text elements will be CSS/JS/HTML positioning and resizing of your choice, depending on how many screen sizes you wish to handle.
Following solution manages responsivity in both vertical and horizontal direction. Furthermore, it does not require additional JS to resize the container div.
Check this fiddle:
https://jsfiddle.net/istibekesi/bm3d1zng/
Highchart sets the height of the chart to 400px by default.
So the trick is to set the height of the chart by percentage:
#container-speed {
height: 180%
}

high chart label outside of view

I am creating a radar chart with high chart and found that one of the labels, Thinking is missing a T after rendering.
Is there anyway I can do to avoid that? My expected solution is to shrink the main chart a bit smaller to fit the outside container. But can we do that automatically? because the outside container varies as the browser resizes (some times even on mobile).
Thanks for any kind of tips!
You can set proper width using min-width and max-width properties of chart container. min-width should be set so that your whole chart is visible. For example:
<div id="container" style="min-width: 600px; max-width: 700px; height: 400px; margin: 0 auto"></div>
See also highchart spider example

Resources