var x1 = new Array();
var x2 = new Array();
var x3 = new Array();
var x4 = new Array();
function sample() {
var query = "SELECT * FROM " +
'13YoMa5RumYGSfM3h2p0anufSw1i62Z3Woqe-bmOw';
var encodedQuery = encodeURIComponent(query);
var url = ['https://www.googleapis.com/fusiontables/v1/query'];
url.push('?sql=' + encodedQuery);
url.push('&key=AIzaSyAH0WCAXRIdHdbI-6bnMSN4kVDDZZmGyqY');
url.push('&callback=?');
$.ajax({
url: url.join(''),
dataType: 'jsonp',
success: function (data) {
var rows = data['rows'];
sx = 0;
for (var i in rows) {
sx = sx + 1;
x3[sx] = rows[i][2] / 1;
x1[sx] = rows[i][0] / 1;
x2[sx] = rows[i][1] / 1;
x4[sx] = rows[i][3] / 1;
}
number = sx;
a1 = 0;
for (s = 1; s < number + 1; s++) {
a1 = a1 + x1[s];
a1 = a1 + x2[s];
a1 = a1 + x3[s];
a1 = a1 + x4[s];
}
a1 = a1 / (number * 4);
b1 = 0;
for (s = 1; s < number + 1; s++) {
b1 = b1 + (x1[s] - a1) * (x1[s] - a1);
b1 = b1 + (x2[s] - a1) * (x2[s] - a1);
b1 = b1 + (x3[s] - a1) * (x3[s] - a1);
b1 = b1 + (x4[s] - a1) * (x4[s] - a1);
}
$("#memo").html(b1);
paint();
}
});
}
function paint(){
str1="<table class=\"mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp\">";
str2="<th class=\"mdl-data-table__cell--non-numeric\">";
str3="<td class=\"mdl-data-table__cell--non-numeric\">";
str=str1;
str=str+"<thead>";
str=str+"<tr>";
str=str+"<th>x1</th>";
str=str+"<th>x2</th>";
str=str+"<th>x3</th>";
str=str+"<th>x4</th>";
str=str+"</tr>"
str=str+"</thead>";
str=str+"<tbody>";
for(s=1;s<number+1;s++){
str=str+"<tr>";
str=str+"<td>"+x1[s]+"</td>";
str=str+"<td>"+x2[s]+"</td>";
str=str+"<td>"+x3[s]+"</td>";
str=str+"<td>"+x4[s]+"</td>";
str=str+"</tr>";
}
str=str+"</table>";
$("#tab2").html(str);
}
最終更新:2016年03月10日 01:24