在调整浏览器大小时,是否有一种简单的方法自动调整jqplot图表的大小?我在谷歌上搜索了很久,但没有找到相关信息。
这里讨论了如何调整jqplots的大小,可以在这里查看。
为使其在浏览器调整大小时正常工作,请将重新绘制函数与window.resize事件绑定:
$(window).resize(function() {
plot1.replot( { resetAxes: true } );
});
运行代码:
$(document).ready(function(){
var plot1 = $.jqplot ('container', [[3,7,9,1,4,6,8,2,5]], {});
$(window).resize(function() {
plot1.replot( { resetAxes: true } );
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.8/jquery.jqplot.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.8/jquery.jqplot.min.css">
<div id="container"></div>
function () {
var plot;
var renderGraph = function() {
plot = $.jqplot('chartId', yourChartData, yourChartOptions);
}
renderGraph();
var resizeGraph = function() {
if (plot)
plot.destroy();
renderGraph();
}
$(window).resize(function() {
resizeGraph();
});
}
replot()
之前。这样我就能确保barWidth
也会被重新缩放。$.each(plot.series, function(index, series) { series.barWidth = undefined; });
- Boro