이 코드를 사용하여 csv 파일에서 Google 차트를 만들려고합니다. 이것은 대부분의 튜토리얼에서 사용되는 코드입니다. 그러나 몇 가지 문제가있어 제대로 실행할 수 없습니다.
// 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
이유를 아는 사람이 있으면 무슨 일이 일어나고 있는지 그리고이 오류에 대한 해결책을 알려주십시오.
이것을 지적 해 주신 @ebyt에게 감사드립니다.
배치
<script src="jquery-csv.js"></script>
jquery를 초기화하고 완벽하게 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다