2014-09-20 56 views
1

我想根据方向调整Jqplot图表的大小。我有下面的代码。它不工作。调整JQPlot图表问题的大小

var plot = $.jqplot('chartDivId', dataArray, options); 
     var w = parseInt($(".jqplot-yaxis").width(), 10) + parseInt($("#chartDivId").widt(), 10); 
     var h = parseInt($(".jqplot-title").height(), 10) + parseInt($(".jqplot-xaxis").height(), 10) + 
    parseInt($("#chartDivId").height(), 10); 
     $("#chartDivId").width(w).height(h); 
     plot.replot(); 

     $(window).on("orientationchange",function(event){ 
     alert("Orientation is: " + event.orientation); 
     plot.replot({ resetAxes: true }); 
    }); 

如果注释掉下面的代码

/* var w = parseInt($(".jqplot-yaxis").width(), 10) + parseInt($("#chartDivId").width(), 10); 
     var h = parseInt($(".jqplot-title").height(), 10) + parseInt($(".jqplot-xaxis").height(), 10) + parseInt($("#chartDivId").height(), 10); 
     $("#chartDivId").width(w).height(h); 
     plot.replot(); 
    */  

我不想注释掉上面的代码,我该怎么解决这个问题它是否行得通呢?

Thanks..Johnson

+0

有人可以回答我的问题吗? – 2014-09-22 07:22:49

+0

嗨@Johnson Tummalapalli,做了以下帮助你吗? – 2014-09-30 04:22:59

+0

你好阿尼什,我很忙,没有机会检查它。我会检查并确认。谢谢你的帮助!! – 2014-10-01 11:15:00

回答

0

变化在DIV /集装箱/窗口的大小变化方向的结果。 所以你可以使用jQuery的resize事件来实现它。

因此,要做到这一点的代码如下。

$(window).on("resize",function(event){ 
    plot.destroy(); // Destroy the chart.. 
    plot.replot(); // Replot the chart with new/old values.. 
}); 

退房这里的工作小提琴:jqPlot Line Chart - Replot on resize event

如果你不能够看到谷歌浏览器的输出(图表),请尝试使用其他浏览器。

如果没有帮助,想让你用更多的代码更新你的代码片段。

希望它有帮助。

+0

你好阿尼什,它仍然没有工作。下面的代码是罪魁祸首。但我不想评论它。 ()(),10)+ parseInt($(“#chartDivId”)。width(),10); (),10)+ parseInt($(“。jqplot-xaxis”)。height(),10)+ parseInt($(“#chartDivId” ).height(),10); $(“#chartDivId”)。width(w).height(h); plot.replot(); – 2014-10-02 06:45:48