2016-07-08 8 views
0

이 코드를 사용하여 csv 파일에서 Google 차트를 만들려고합니다. 이 코드는 대부분의 자습서에서 사용되는 것으로 나타났습니다. 그러나 거기에 몇 가지 문제로 인해, 나는 그것을 제대로 실행할 수 없습니다.Google Charts API : 'toArrays'속성을 읽을 수 없습니다. 정의되지 않음

 // Load the Visualization API and the corechart package. 
     google.charts.load('current', {'packages':['corechart']}); 

     // Set a callback to run when the Google Visualization API is loaded. 
     google.charts.setOnLoadCallback(drawChart); 

     // Callback that creates and populates a data table, 
     // instantiates the pie chart, passes in the data and 
     // draws it. 
     function drawChart() { 
    // grab the CSV 
     $.get("Chart1-data.csv", function(csvString) { 
     // transform the CSV string into a 2-dimensional array 
     var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar}); 

     // this new DataTable object holds all the data 
     var data = new google.visualization.arrayToDataTable(arrayData); 

     // this view can select a subset of the data at a time 
     var view = new google.visualization.DataView(data); 
     view.setColumns([0,1]); 

    // set chart options 
    var options = { 
     title: "A Chart from a CSV!", 
     hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max}, 
     vAxis: {title: data.getColumnLabel(1), minValue: data.getColumnRange(1).min, maxValue: data.getColumnRange(1).max}, 
     legend: 'none' 
    }; 

    // create the chart object and draw it 
    var chart = new google.visualization.ScatterChart(document.getElementById('chart_div')); 
    chart.draw(view, options); 
    }); 
} 

나는이 튜토리얼로갑니다. 아무도 그 이유를 알고 있다면

Uncaught TypeError: Cannot read property 'toArrays' of undefined 

이 날 일이 뭐죠 알려 주시기 바랍니다이 오류에 대한 해결책 :하지만 웹 서버에 실행에 나에게 다음과 같은 오류를 제공합니다.

+0

무엇이 $ .csv입니까? – ebyt

+0

@ebyt API 문서는 https://github.com/evanplaice/jquery-csv/blob/master/docs/api.md –

+1

에서 가져 왔습니까? '' – ebyt

답변

2

감사합니다. 이것을 설명해 주신 @ebyt.

는 jQuery를 초기화 한 후
<script src="jquery-csv.js"></script> 

을 배치하고 완벽하게 작동합니다.

+0

이것은 훌륭합니다. 내 것이 정확히 같지는 않았지만 예, 스크립트의 순서를 다시 정렬하는 것이 해결책 일 수 있습니다. –

+1

@Max von Hippel 기꺼이 도와 드리겠습니다! –

관련 문제