Javascript 列的可视性

Javascript 列的可视性,javascript,javascript-events,dygraphs,Javascript,Javascript Events,Dygraphs,我正在尝试更改动态图表列的可见性 这项工作: function drawChart() { data = getData(); window.chart1 = new Dygraph.GVizChart( document.getElementById('dygraphs')).draw(data, { }); } function drawChart() { data = getData(); window.chart1 = new Dygraph.

我正在尝试更改动态图表列的可见性

这项工作:

function drawChart() {
  data = getData();
  window.chart1 = new Dygraph.GVizChart(
       document.getElementById('dygraphs')).draw(data, {
    });
  }
function drawChart() {
  data = getData();
  window.chart1 = new Dygraph.GVizChart(
       document.getElementById('dygraphs')).draw(data, {
            visibility: [false, true, true, true]
    });
  }
这也适用于:

function drawChart() {
  data = getData();
  window.chart1 = new Dygraph.GVizChart(
       document.getElementById('dygraphs')).draw(data, {
    });
  }
function drawChart() {
  data = getData();
  window.chart1 = new Dygraph.GVizChart(
       document.getElementById('dygraphs')).draw(data, {
            visibility: [false, true, true, true]
    });
  }
但是在
图纸
中,在代码之后,当我添加以下行时

function drawChart() {
  data = getData();
  window.chart1 = new Dygraph.GVizChart(
       document.getElementById('dygraphs')).draw(data, {
    });
    window.chart1.setVisibility(0, true);
    window.chart1.setVisibility(1, false);
  }
我得到错误:
UncaughtTypeError:无法调用未定义的方法“setVisibility”。图纸

阅读之后,我想可能是
chart1
在执行时还没有准备好。所以我添加了这个函数:

    function showChange() {
        alert('show chart1:' + window.chart1);
        window.chart1.setVisibility(3, false);
    }

  <a href="#" onclick='showChange();return false;'>showChange</a>
函数showChange(){
警报(“显示图表1:”+窗口.chart1);
window.chart1.setVisibility(3,false);
}
但是,当我单击
showChange
链接时,我得到了相同的错误:
uncaughttypeerror:无法调用未定义的方法“setVisibility”


警报窗口显示:show chart1:undefined
新建动态图表。GVizChart()
返回一个对象
.draw()
不会

你想要的东西更像:

window.chart1=new Dygraph.GVizChart(document.getElementById('dygraphs');
window.chart1.draw(数据,{});
您还将遇到问题,因为dygraphs GViz包装器没有
setVisibility()
方法。要使代码正常工作,您需要获取底层动态图对象:

函数showChange(){
警报(“显示图表1:”+窗口.chart1);
window.chart1.date_graph.setVisibility(3,false);
}