Phi*_*ipp 7 html javascript highcharts
在我的网页上是用Highchart绘制的图表.现在,如果我调整整个窗口的大小,我希望此图表调整其大小(尤其是宽度).该守则看起来类似于:
window.onresize=function(){resized();}
function resized()
{
$("#container").highcharts().redraw();
}
Run Code Online (Sandbox Code Playgroud)
如果我覆盖重绘事件(使用类似"alert("resized");"),我将得到一个结果,因此应该调用该方法 - 但图表不会改变其大小.我还尝试手动设置图表大小
$("#container").highcharts().setSize(width, height, false);
Run Code Online (Sandbox Code Playgroud)
但两种方式都不起作用.还有其他解决方案吗?
小智 2
您是否尝试以这种方式编写代码,以便它会在窗口大小调整时自动处理图表大小调整。
// create the chart
var chart = Highcharts.chart('container', {
chart: {
events: {
redraw: function () {
var label = this.renderer.label('The chart was just redrawn', 100, 120)
.attr({
fill: Highcharts.getOptions().colors[0],
padding: 10,
r: 5,
zIndex: 8
})
.css({
color: '#FFFFFF'
})
.add();
setTimeout(function () {
label.fadeOut();
}, 1000);
}
}
},
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]
}]
});
Run Code Online (Sandbox Code Playgroud)