javascript - How can I have a responsive graph with highcharts? -
basically, have container divided col-xs-3, col-xs-7(which holds graph), , col-xs-2 , , 3 tables underneath same bootstrap classes(col-xs-3,...). on container have graph created highcharts, , want aligned table underneath(as shown purple arrows),this want result, , responsive when window width changes:
right have this:
i tried approches moving graph left, scale graph on different media queries, these work on specific width.
highcharts.chart('container', { chart: { renderto: '' }, title: { text: '' }, credits: { enabled: false }, xaxis: { linewidth: 0, minorticklength: 0, ticklength: 0, labels: { rotation: -45, enabled: false }, //maxzoom: 24 * 3600 * 1000 * 30, // fourteen days title: { //text: 'sample' } }, yaxis: { min: 0, max: 150, tickinterval: 50, gridlinewidth: 0, linewidth: 4, plotlines: [{ color: '#ccc', dashstyle: 'dash', width: 2, value: 100 }], title: { text: '' }, labels: { style: { color: '#ccc' }, formatter: function () { if ('100' == this.value) { return '<span style="fill: #000;">' + this.value + ' %</span>'; } else { return this.value + ' %'; } } } }, tooltip: { shared: true, formatter: function () { var result = '<b>' + highcharts.dateformat('%b %e, %y', this.x) + '</b>'; $.each(this.points, function (i, datum) { result += '<br />' + math.round(datum.y) + ' %'; }); return result; } }, legend: { enabled: false, }, plotoptions: { line: { marker: { enabled: false } } }, series: [{ name: '', data: [[0, 50.57], [10, 50.63], [20, 75.14], [30, 100.08], [40, 40.28], [130, 68.25], [140, 125.01], ], linewidth: 5, threshold: 99, step: 'center', tooltip: { valuedecimals: 2 } }] });
.empty { background-color: #f3f3f3; height: 250px; } .row { margin: 10px 0; }
<script src="https://code.highcharts.com/highcharts.js"></script> <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="row"> <div class="col-xs-3 empty"></div> <div class="col-xs-7" style=""> <div id="container" style="height: 250px; width: 100%"></div> </div> <div class="col-xs-2 empty"></div> </div> <div class="row"> <div class="col-xs-3 empty"></div> <div class="col-xs-7" style=""> <div id=""></div> </div> <div class="col-xs-2 empty"></div> </div> </div>
here jsfiddle of code
i solved making few changes chart. these things changed:
in js file:
chart: { renderto: 'chartcontainer' }
in html file:
<div id="container" style="height: 250px;width:calc(100% + 90px);"></div>
in css file:
.highcharts-container { left: -70px; }
here jsfiddle.
Comments
Post a Comment