2013-08-06 3 views
0

내 var 컨트롤 = new google.visualization.ControlWrapper ({controlType : 'ChartRangeFilter', containerId : '컨트롤')이 보이고 내 (var ComboChart = new google.visualization.ChartWrapper ({chartType : 'ComboChart', containerId : 'chart1') 내 페이지에서이 오류가 발생했습니다 (한 명 이상의 참가자가 그리기에 실패했습니다) 콘솔에서이 오류가 발생했습니다 ([15:34 : 41596] 몇명 셰네 보라 ETE transmise à«에서 getElementById())컨트롤 및 대시 보드로 제어하는 ​​하나의 COMBOCHART

이 내 코드입니다 :

!function($) { 

    //google.load('visualization', '1.0', {'packages':['table']}); 
    google.load('visualization', '1', {packages: ['corechart']}); 
    google.load('visualization', '1.1', {packages: ['controls']}); 
    google.setOnLoadCallback(initialize); 


    function populateSelectWithOptions(target, data) 
    { 
     console.log(data, typeof(data)); 
     var $select =$("#"+target); 
     $select.empty(); 
     for(var i=0; i <data.length;i++){ 
     $select.append($("<option>").attr("value", data[i]).text(data[i])); 
     } 

     $select.prop('disabled', false); 
     $select.change(function(){ 
      var e = document.getElementById("groupe"); 
      var strUser = e.options[e.selectedIndex].value; 
      //alert(strUser); 
      sendQuery(strUser) 

     }); 

     // baraie inke vaghti bara avalin bar safe lod mishavad dar chekbox chizi vojod dashte bashad 
     $select.trigger('change'); 
     //console.log(populateSelectWithOptions(target, data)); 
     }; 


     function sendQuery(cityName) { 
      // You can manipulate the variable response 
      // Success! 
      var query = new google.visualization.Query('http://api.XXX.com/XXX/datasource?table='+cityName); 

      query.setQuery("select (cost_reportings_timestamp), sum (cost_reportings_cost) group by (cost_reportings_timestamp) pivot ecoadmin_zone_name"); 
      //Send the query with a callback function. 
      query.send(drawChart); 
     //console.log(response); 
     } 


     function drawChart(response) { 
      if (response.isError()) { 
      alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); 
      return; 
     } 
      var data = response.getDataTable(); 
      console.log(data); 

      var control = new google.visualization.ControlWrapper({ 
        controlType: 'ChartRangeFilter', 
        containerId: 'control', 
        options: { 
         // Filter by the date axis. 
         filterColumnLabel: 'cost_reportings_timestamp', 
         ui: { 
          chartType: 'LineChart', 
          chartOptions: { 
           chartArea: { 
            width: '90%' 
           }, 
           hAxis: { 
            baselineColor: 'none' 
           } 
          }, 
          // Display a single series that shows the closing value of the stock. 
          // Thus, this view has two columns: the date (axis) and the stock value (line series). 
          chartView: { 
           columns: [0,1] 
          } 
         } 
        }, 
        //Initial range: 2010 to 2021 
        state: { 
         range: { 
          start: new Date(2012), 
          end: new Date(2019) 
         } 
        } 
       }) 

      // Define a bar chart 
       var ComboChart = new google.visualization.ChartWrapper({ 
        chartType: 'ComboChart', 
        containerId: 'ComboChart', 
        options: { 
         width: 400, 
         height: 300, 
         seriesType: 'bars', 
         isStacked:'True', 
         hAxis: { 
          minValue: 0, 
          maxValue: 60 
         }, 
         chartArea: { 
          top: 0, 
          right: 0, 
          bottom: 0 
         }, 
        }, 
        view: {columns: [0, 1, 2, 3]} 
       }); 

      // Create the dashboard.  
       var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard')). 
       // Configure the slider to affect the bar chart 
       bind([control], [ComboChart]). 
       // Draw the dashboard 
       draw(data); 




     } 
     function initialize() { 
      var $newDiv = $('<div>').attr('id','ComboChart');    
      $('#ComboChart').append($newDiv); 

      $($newDiv).hide(); //hide the div here 

      // Replace the data source URL on next line with your data source URL. 
      // Specify that we want to use the XmlHttpRequest object to make the query. 
      getTable(); 
     } 
      // baraie inke vaghti ro elemenha click mikonim piecharto ieshon bede 
      $("#groupe").change(function() { 
      $('#ComboChart').toggle(); //If it is visible hide it or vice versa 
       //.. 
     }); 

    function getTable() { 
      $.getJSON('call/json/mytables', {}, function (response){ 
      console.log(response); 
      populateSelectWithOptions("groupe", response); 
     }) 
     } 

}(jQuery); 

답변

1

이 Google 시각화 API의 foru에 게시 된 문제에 대한 중복 된 것으로 보인다

  1. 당신이 옵션이있는 <select> 요소를 채우기 다음 바로 "변화"를 발사하고 있습니다 : 여기 몇 가지 잠재적 인 문제를 참조

    : MS (here는)하지만 StackOverflow의 군중을 위해, 여기 내 반응이다 선택된 <option>이있을 것으로 예상되는 이벤트 핸들러이지만 기본 선택 옵션을 설정하지 않으므로 null이 반환됩니다 (또는 브라우저가 얼마나 까다로울 지에 따라 정의되지 않거나 오류가 발생 함).

  2. "ComboChart"라는 ID로 새 div를 만들고 ID를 "ComboChart"로하여 div에 추가하려고합니다. "ComboChart"가 이미있는 경우 요소에 고유 ID가 있어야하는 HTML 규칙을 위반하게됩니다 (이 경우이 문제가 발생할 수 있음). "ComboChart"가 아직 존재하지 않으면 새 div를 DOM에 추가하지 못하므로 차트에 아무 것도 표시되지 않습니다.
  3. 시각화 API는 다른 함수 호출에서로드 될 때 문제가 있습니다. 두 번 시각화 API를로드하려고
  4. 다른 기능의 외부 google.loadgoogle.setOnLoadCallback 통화가 안전을 위해 남겨주세요 :

    때 한 번만로드해야합니다. 대시 보드 기능, ControlWrappers 및 ChartWrappers를 사용하려면 "controls"패키지가 필요합니다.

    google.load('visualization', '1', {packages: ['controls']}); 
    
: 당신이 릴리스 후보를 사용하는 몇 가지 특별히 필요하지 않으면, 당신은 버전 1을로드해야합니다