Javascript examples for highcharts:Line Chart
Automated y-axis-title-offset in line chart for varying length of y-axis title?
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> txt = "Very important data here but if very long different when short blab blab bla bla"; $(function () {//from w w w . j av a 2s. c o m $('#container').highcharts({ chart: { events: { load: function () { console.log(this.yAxis[0]); var chart = this, yAxis = chart.yAxis[0], tp = yAxis.tickPositions, firstLabel = yAxis.ticks[tp[0]].label.getBBox().width, lastLabel = yAxis.ticks[tp[tp.length - 1]].label.getBBox().width, bb = yAxis.axisTitle.getBBox(); yAxis.update({ title: { offset: -bb.width + (firstLabel > lastLabel ? firstLabel : lastLabel) } }); } } }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, yAxis: { title: { text: "Very important data here but if very long different when short blab blab bla bla", align: 'high', rotation: 0, //offset: txt.length * -5.5, rotation: 0, y: -15 } }, 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] }] }); }); </script> </head> <body> <script src="https://code.highcharts.com/highcharts.js"></script> <div id="container" style="height: 400px"></div> </body> </html>