2013-03-06 2 views
0

Dygraph GVizChart 열의 가시성을 변경하려고합니다.Dygraphs set 열의 유효성

이 작동 :

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] 
    }); 
    } 

그러나 내부 drawChart, 즉 코드 뒤에, 나는 다음 줄을 추가 할 때,

function drawChart() { 
    data = getData(); 
    window.chart1 = new Dygraph.GVizChart(
     document.getElementById('dygraphs')).draw(data, { 
    }); 
    window.chart1.setVisibility(0, true); 
    window.chart1.setVisibility(1, false); 
    } 

내가 오류가 발생합니다 : Uncaught TypeError: Cannot call method 'setVisibility' of undefined. drawChart

this question을 읽은 후 실행시에 chart1이 준비되지 않았을 수도 있습니다. 그래서이 기능을 추가 :

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

    <a href="#" onclick='showChange();return false;'>showChange</a> 

을하지만 showChange 링크를 클릭 할 때, 나는 같은 오류가 발생합니다 : Uncaught TypeError: Cannot call method 'setVisibility' of undefined
그리고 경고 창이 show chart1: undefined

답변

1

new Dygraph.GVizChart() 객체를 반환 말한다. .draw() 않습니다. 당신은 또한 dygraphs GViz 래퍼가 setVisibility() 방법이 없기 때문에 문제가 실행하는거야

window.chart1 = new Dygraph.GVizChart(document.getElementById('dygraphs')); 
window.chart1.draw(data, {}); 

:

당신은 더 뭔가를 원한다. 코드가 작동하려면 기본 Dygraph 객체를 가져와야합니다.

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