加载图表时显示旋转图像

时间:2015-10-21 21:08:02

标签: javascript jquery html plot dygraphs

我想在加载dygraphs图时显示一个微调器(来自spin.js)。到目前为止它的工作原理,但我不能说旋转图像显示在渲染图表的div中。如果我使用另一个空div容器('testdiv')进行旋转 - 一切都很好。

这是我的代码:

<input type="radio" id="r1" name="radiogroup" value="2012" checked="checked" />2012
<input type="radio" id="r2" name="radiogroup" value="2013" />2013

<div id="graph1" style="width:700px; height:400px;"></div>
<div id="testdiv"></div>

<script type="text/javascript">

$(document).ready(function() {

  $("input[name=radiogroup]:radio").click(function() {
    var target = document.getElementById('testdiv');
    var spinner = new Spinner().spin(target);

    var year = $(this).val()

    var g1 = new Dygraph(
      document.getElementById("graph1"),year+".csv",
      { }
    );

    g1.ready(function () {
      spinner.stop();
    });
  });

  $("input:radio[name=radiogroup][value=2012]").click();   
});

</script>

因此,如果我将此行更改为div“graph1”,它将停止工作:

var target = document.getElementById('graph1');

看小提琴: http://jsfiddle.net/hp4t8hap/

1 个答案:

答案 0 :(得分:0)

我不确定这是最好的主意,但我使用了drawCallback函数,现在如果它是第一次回调:

drawCallback: function(dygraph, isInitial) { if(isInitial) $("#loading").slideUp(function() { $("input[type='checkbox']").removeAttr("readonly"); canLoadData = true; $("button").removeAttr("disabled"); $("button > i").remove(); }); },

相关问题