score:13
This should be done with just CSS... no resizing functions.
try adding position:absolute
to your chart css property
The new css for #chart
would look like this:
#chart {
display: table-cell;
position:absolute;
width:50%;
}
I think this is the effect you want.
Check my Fiddle
note: I removed all resizing Javascript
Follow Up:
If you need to resize Highcharts on window resize with animation, you can do it with this syntax.
$(window).resize(function() {
height = $(window).height()
width = $(window).width() / 2
$("#chart").highcharts().setSize(width, height, doAnimation = true);
});
I think this is more what you wanted using the Highchart setSize
method with animation instead of CSS)
Fiddle
score:0
try to use this Fiddle
i am not sure how much it will help you, i have just used Highcharts some of the functionality.
Note: Resize the window of jsfiddle and run it will adjust according to the window i am not sure why it is behaving like this
Html
<div class="wrapper">
<div class="element">
<div id="container" style="width:100%;margin: 0 auto"></div>
</div>
Javascript
$(function () {
$('#container').highcharts({
chart: {
type: 'line',
marginRight: 130,
marginBottom: 25
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
CSS // i am not passing any css
.wrapper {
display: table;
width: 100%;
}
.element {
display: table-cell;
width: 50%;
}
Please refer this link where Highchart is responsive http://jsfiddle.net/2gtpA/show/
score:0
To be honest, I'm not quite sure why your chart was not resizing properly. But I have a way to do this without resizing in JS, assuming you can set the height of your wrapper div.
First of all, you really shouldn't style your elements as tables if you are not using tabular data; I removed this from your CSS. Secondly, if you want your legend centered, it really should be within a separate element that is alongside the chart; each should be wrapped in the same kind of div. Normally I'd call this a column, but since you're already using .element, that works too. These will each be floated to the left, with a width of 50%, and a height of 100% (this is important, because we can't center the legend vertically unless its parent has a height defined.
Then we have a child div inside the second .element, which is given the .legend class. Now we can more easily position it within that space. Since you don't know the height of the legend, you can't use a negative margin of 50%. Instead, you can use a CSS3 transform. It looks like this:
.legend {
position: relative;
top: 50%; /* relative to parent */
-webkit-transform: translateY(50%); /* relative to the element itself */
transform: translateY(50%);
}
JSFiddle here
This works well because the position is based on the parent element (or the closest ancestor with a defined position, but in this case, that would be the parent), and the transform is based on the element itself. So this will work regardless of the legend's height, your chart will resize properly, and you don't need to use JS to do it.
score:0
You shouldn't use any JS code. If you want the charts to become responsive, here's the code:
http://jsfiddle.net/L9gubqvy/12/
Here's the CSS:
.wrapper {
display: table;
width: 100%;
float:none;
clear:both;
}
.wrapper:after {
visibility:hidden;
display:block;
font-size:0;
content:" ";
clear:both;
height:0;
}
.element {
display: table-cell;
width: 50%;
}
#chart {
width: 100%;
}
.legend {
display: table-cell;
width: 50%;
vertical-align: middle;
}
PS: I'm having trouble posting the code using StackOverflow Code Snippet. I'll update the code later on.
score:1
Something like this? For me, use perfect.
CSS:
.wrapper {
display: table;
width: 100%;
}
.element {
display: table-cell;
width: auto;
}
#chart {
width: 100%;
}
.legend {
display: table-cell;
width: 70px;
vertical-align: middle;
}
JS:
$('#chart').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
$(window).resize(function() {
$('#chart').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
score:1
Here is a working Fiddle
The trick is to add two CSS properties:
- The wrapper
element
gets aposition: relative;
- The chart div
chart
gets aposition:absolute;
score:3
Instaed of table cell, why you cannot use default divs with the float:left
option?
.wrapper {
float:left;
width: 100%;
}
.element {
float:left;
width: 50%;
}
#chart {
width: 100%;
}
.legend {
width: 50%;
float:left;
}
Example: http://jsfiddle.net/L9gubqvy/4/
score:4
svg image prevents the table-cell
to get smaller. Solution for this is:
.highcharts-container, .highcharts-container svg {
width: 100% !important;
}
See the example http://jsfiddle.net/FzXEM/9/
There are other ways to make the chart resize correctly like using float: left
or position: absolute
but then there are other problems and you can only use vertical-align
in table or inline layouts.
Source: stackoverflow.com
Related Query
- Highcharts: Chart does not resize properly by making the screen smaller
- How to make a HighCharts drilldown column/bar chart that does not hide the non-drilldown categories
- Display of plotted point labels not appearing properly on X Range Chart for the first date of month - Highcharts
- Highcharts userOptions does not update after changing the chart title
- How to modify the code so that Highcharts graph does not cover fixed navigation bar at the top of the page?
- Highcharts When printing the chart does not fit the page
- Highcharts chart does not show the value of y
- Highcharts does not resize charts inside tabs
- HighCharts chart export (screenshot download) does not display Navigator graph
- Customise Highcharts Pie Chart Selection State so that slice does not animate out when selected
- jspdf is not able to capture the div content properly for highcharts to download as pdf format
- Highcharts Line Chart Drill down not working properly
- Highcharts multiple x axis and yaxis. The width of the 1st x-axis is not in sync with browser resize
- Why does my addSeries (in highcharts) only display names of the series but not the actual pie chart itself
- tooltip in highcharts does not work properly
- Highcharts Chart is not completely hidden if the smartGWT Layout id hidden
- Does not return data as intended when creating the chart
- HighCharts : Tooltips exist but line is not drawn in the chart
- HighCharts line series not displaying properly with stacked bar combo chart
- highcharts tooltip not working properly for hacked gantt chart
- Pie chart from highcharts does not render via justpy
- Highcharts: yAxis.height does not scale drawable area, causing graph to go off the chart
- HighCharts title styles i.e textDecoration property not applying when we export the chart using canvg
- highcharts from HTML table does not getting the x axis key
- HIghcharts - chart width not the size of the parent container
- Tooltips does not appear properly in Highcharts ganttchart
- Destroy method does not reset the chart index
- Highcharts polar chart not connecting lines properly
- Highcharts dynamic set category update the chart but shows only points but not lines
- Added series does not remains in highcharts on show/hide of chart container
More Query from same tag
- HighCharts Adding a Back Button when data is set through point.events.click
- Use Node.js as data source for highcharts
- Highcharts adding labels/columns with no data
- Highcharts area charts with single data, not rendering
- HighCharts Keep Vertical Line on Click Event
- How to display single hightchart bar graph in multiple container/selector?
- Setting the top value for a highcharts chart
- Drilldown in HighChart on Double Click
- Printing from Highcharts returns focus to the top of the page
- Show data labels on top in stacked column graph in highcharts
- Highcharts xAxis text matching series name
- Highcharts - TypeError: Cannot read property 'isResponsiveOptions' of null
- Can't assign names to legend points
- Highcharts pie/bar combo. How to load json and how are the data series expressed
- Populate Highchart using json data in Angular js
- Highcharts: Show x axis for missing data but ignoring certain area
- How to display same data points in a same series in highcharts?
- Legend overlapping on drilldown pie chart
- Highcharts - "Style is null or not an object"
- Highcharts with Google Analytics Oauth 2.0
- Chart js pie or doughnut charts 3 inside instead of 1
- Highcharts x-axis category overlap
- Highcharts Angular update chart with new options - including linked series
- Highchart plugin does not work
- HIghcharts Treemap Groupby leaf objects at Level 1(Parent) and group by child at Level1(Sub objects)with custom color coding
- Add label in into square Highcharts Gant
- Updating a Highchart from a form with a click() event in jquery
- Adding dynamic mean to time series chart
- Using Highcharts, I want to overlay a line showing the optimal value for a bar
- Multidimensional JSON to javascript array for highcharts