Skip to content

Instantly share code, notes, and snippets.

@JacobWeinbren
Created September 14, 2014 19:18
Show Gist options
  • Save JacobWeinbren/b8ee95477211a019e399 to your computer and use it in GitHub Desktop.
Save JacobWeinbren/b8ee95477211a019e399 to your computer and use it in GitHub Desktop.
$( document ).ready(function() {
Sijax.request("data", []);
});
function loaded() {
var checkExist = setInterval(function() {
if (typeof google == "object") {
var options = {packages: ["corechart"], callback : loadGoogle};
google.load("visualization", "1", options);
clearInterval(checkExist);
}
}, 100);
var random = Math.floor(Math.random()*$("#a option").length);
$("#a option").eq(random).attr("selected", "selected");
var random = Math.floor(Math.random()*$("#b option").length);
$("#b option").eq(random).attr("selected", "selected");
$("#a").change(function() {
Sijax.request("chart", [$("#a").val(), $("#b").val()]);
});
$("#b").change(function() {
Sijax.request("chart", [$("#a").val(), $("#b").val()]);
});
}
function loadGoogle() {
Sijax.request("chart", [$("#a").val(), $("#b").val()]);
}
function drawChart(x, y, database, range_x, range_y, names) {
array = []
for (var i = 0; i < database.length; i++) {
name = names[i];
item = [database[i][0],database[i][1], name]
array.push(item);
}
$(".meter").animate({width:"75%"}, function () {
var data = new google.visualization.DataTable();
data.addColumn("number", x);
data.addColumn("number", y);
data.addColumn({type: "string", role: "tooltip"});
data.addRows(array);
var options = {
title: x + " vs. " + y + " comparison",
hAxis: {title: x, minValue: range_x[0], maxValue: range_x[1]},
vAxis: {title: y, minValue: range_y[0], maxValue: range_y[1]},
legend: {position: "none"},
trendlines: {
0: {
color: "green",
lineWidth: 10,
opacity: 0.2,
type: "polynomial",
degree: 3
}
}
}
$(".meter").animate({width:"80%"}, function() {
var chart = new google.visualization.ScatterChart(document.getElementById("chart"));
$(".meter").animate({width:"90%"}, function() {
chart.draw(data, options);
$('#chart').hide();
$('#chart').addClass('animated bounceInUp');
$('#chart').show(function() {
$(".meter").animate({width:"100%"});
setTimeout(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
}, 2000);
});
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment