为什么我的图表 (jqplot) 在与 zk 集成时按下按钮后才会渲染?

发布于 2024-10-28 08:10:02 字数 2725 浏览 0 评论 0原文

我使用 zk 来显示页面,作为该页面的一部分,我包含一个 html/js 页面,其中包含我想要使用 jqplot 显示的图表。

如果我单独加载 html 文件,绘图就会显示得很好。当我将它包含在 zul 页面中时,它无法显示。但是,确实出现了一个重置​​按钮(它重置图表上的缩放级别)。如果我点击该按钮,图表就会正常显示。

我不知道为什么会发生这种情况或如何解决它。有人有什么想法吗?

test.html...

<span id="test">Test2</span>
<div class="jqPlot" id="chart1" style="height:300px; width:400px;"></div>

<button onclick="plot.resetZoom();">Reset</button>

<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/plugins/jqplot.cursor.js"></script>
<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/plugins/jqplot.dateAxisRenderer.js"></script>


<script type="text/javascript" language="javascript">
  $(document).ready(function(){
  $.jqplot.config.enablePlugins = true;

    var goog = [["6/22/2009",425.32],
    ["6/8/2009",424.84],
    ["5/26/2009",417.23],
    ["5/11/2009",390],
    ["9/2/2008",444.25],
    ["8/27/2007",515.25]];

   plot = $.jqplot('chart1', [goog], { 
    // title: 'Google, Inc.', 
    series: [{ 
        // label: 'Google, Inc.', 
        neighborThreshold: -1 
    }], 
    axes: { 
        xaxis: { 
            renderer:$.jqplot.DateAxisRenderer, 
            min:'August 1, 2007', 
            tickInterval: '4 months', 
            tickOptions:{formatString:'%Y/%#m/%#d'} 
        }, 
        yaxis: { 
            renderer: $.jqplot.LogAxisRenderer, 
            tickOptions:{formatString:'$%.2f'} 
        } 
    }, 
    cursor:{show:true, zoom:true} 
 });
});
</script>

还有我的测试 zul 页面...

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?page zscriptLanguage="GroovyGrails"?>

<zk xmlns="http://www.zkoss.org/2005/zul"
    xmlns:h="http://www.w3.org/1999/xhtml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.zkoss.org/2005/zul
 http://www.zkoss.org/2005/zul/zul.xsd">  

<window apply="zk.test.indexComposer">

<hbox>
  <image src="${z.resource(dir:'images', file:'grails_logo.png')}"/>
</hbox>

<tabbox height="100%">
  <tabs id="tabs">
    <tab id="tabinfo" label="Tab1" />
  </tabs>
  <tabpanels id="tabpanel1">
    <tabpanel>
      <include mode="defer" src="/js/jqplot/examples/test.html"/>
    </tabpanel>
  </tabpanels>
</tabbox>

I am using zk to display a page and as part of that I include an html/js page that holds the chart I want to display using jqplot.

If I load the html file by itself the plot shows up fine. When I include it in the zul page, it fails to show up. However there is a reset button (it resets the zoom level on the chart) that does appear. If I hit that button, the chart shows up fine.

I have no idea why this is happening or how to fix it. Does anyone have any ideas?

test.html...

<span id="test">Test2</span>
<div class="jqPlot" id="chart1" style="height:300px; width:400px;"></div>

<button onclick="plot.resetZoom();">Reset</button>

<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/plugins/jqplot.cursor.js"></script>
<script language="javascript" type="text/javascript" src="/zk-test/js/jqplot/plugins/jqplot.dateAxisRenderer.js"></script>


<script type="text/javascript" language="javascript">
  $(document).ready(function(){
  $.jqplot.config.enablePlugins = true;

    var goog = [["6/22/2009",425.32],
    ["6/8/2009",424.84],
    ["5/26/2009",417.23],
    ["5/11/2009",390],
    ["9/2/2008",444.25],
    ["8/27/2007",515.25]];

   plot = $.jqplot('chart1', [goog], { 
    // title: 'Google, Inc.', 
    series: [{ 
        // label: 'Google, Inc.', 
        neighborThreshold: -1 
    }], 
    axes: { 
        xaxis: { 
            renderer:$.jqplot.DateAxisRenderer, 
            min:'August 1, 2007', 
            tickInterval: '4 months', 
            tickOptions:{formatString:'%Y/%#m/%#d'} 
        }, 
        yaxis: { 
            renderer: $.jqplot.LogAxisRenderer, 
            tickOptions:{formatString:'$%.2f'} 
        } 
    }, 
    cursor:{show:true, zoom:true} 
 });
});
</script>

And my test zul page...

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?page zscriptLanguage="GroovyGrails"?>

<zk xmlns="http://www.zkoss.org/2005/zul"
    xmlns:h="http://www.w3.org/1999/xhtml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.zkoss.org/2005/zul
 http://www.zkoss.org/2005/zul/zul.xsd">  

<window apply="zk.test.indexComposer">

<hbox>
  <image src="${z.resource(dir:'images', file:'grails_logo.png')}"/>
</hbox>

<tabbox height="100%">
  <tabs id="tabs">
    <tab id="tabinfo" label="Tab1" />
  </tabs>
  <tabpanels id="tabpanel1">
    <tabpanel>
      <include mode="defer" src="/js/jqplot/examples/test.html"/>
    </tabpanel>
  </tabpanels>
</tabbox>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩于岁月 2024-11-04 08:10:02

这是一个时间问题,请替换

the $(document).ready(function() {

zk.afterMount(function(){
    if (zk.mounting !== false) {
        zk.afterMount(arguments.callee);
        return;
    }

that is a timing issue, please replace

the $(document).ready(function() {

with

zk.afterMount(function(){
    if (zk.mounting !== false) {
        zk.afterMount(arguments.callee);
        return;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文