|
<!DOCTYPE html> |
|
|
|
<html> |
|
<head> |
|
<title>DBVisualization</title> |
|
<meta charset = "utf-8"> |
|
<script src="http://d3js.org/d3.v3.min.js" ></script> |
|
<script src="https://www.google.com/jsapi"></script> |
|
<script>google.load("visualization", "1", {packages:["corechart"]});</script> |
|
<style> |
|
#text_div { |
|
width = 80%; |
|
height = 400px; |
|
} |
|
#greeting { |
|
background-color: #F8F8F8; |
|
font-family: 'Open Sans', sans-serif; |
|
font-size: 24px; |
|
margin: 15px; |
|
} |
|
#chart_div { |
|
width: 100%; |
|
height: 800px; |
|
} |
|
|
|
</style> |
|
</head> |
|
|
|
<body> |
|
<div id = "text_div"></div> |
|
<form> |
|
<table> |
|
<tr> |
|
<td>x: </td><td><select id = "xValue"></select></td> |
|
</tr> |
|
<tr> |
|
<td>y: </td><td><select id = "yValue"></select></td> |
|
</tr> |
|
<tr> |
|
<td>color: </td><td><select id = "colorValue"></select></td> |
|
</tr> |
|
<tr><td>label: </td><td><select id = "labelValue"></select></td></tr> |
|
<tr> |
|
<td>bubble size: </td><td><select id = "bubbleValue" ></select></td> |
|
</tr> |
|
<tr><td>Normalize variable</td><td><select id = "norm"></select></td></tr> |
|
<tr><td>Normalize unit</td><td><input id = "nunit" type = "text"></td></tr> |
|
</table> |
|
</form> |
|
<button id = "load" onclick= "loadData()">Load Data</button> |
|
<br> |
|
<button id = "draw" onclick= "drawChart()">Draw Chart</button> |
|
<div id = "chart_div"></div> |
|
<script> |
|
var vartext = ""; |
|
d3.tsv("yogurt.tsv", function(err, dat){ |
|
|
|
for (key in dat[1]) { |
|
vartext = vartext + key + "\n"; |
|
} |
|
//var element = document.getElementById("text_div"); |
|
//element.innerText = vartext; |
|
var optiondata = d3.keys(dat[1]); |
|
optiondata.unshift(""); |
|
|
|
|
|
d3.select("#xValue").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
d3.select("#yValue").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
d3.select("#colorValue").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
d3.select("#labelValue").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
d3.select("#bubbleValue").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
d3.select("#norm").selectAll("option").data(optiondata).enter().append("option").attr("value",function(d){return d;}).append("text").text(function(d){return d;}); |
|
|
|
}); |
|
|
|
var datatable = new Array(); |
|
function loadData(){ |
|
if (datatable.length != 0) { |
|
datatable.length = 0; |
|
} |
|
var column0 = document.getElementById("labelValue").value; |
|
if (column0 == null){ |
|
alert("column0 is empty!"); |
|
} |
|
|
|
var column1 = document.getElementById("xValue").value; |
|
if (column1 == null){ |
|
alert("column1 is empty!"); |
|
} |
|
var column2 = document.getElementById("yValue").value; |
|
if (column2 == null){ |
|
alert("column2 is empty!"); |
|
} |
|
var column3 = document.getElementById("colorValue").value; |
|
if (column3 == null){ |
|
alert("column3 is empty!"); |
|
} |
|
var column4 = document.getElementById("bubbleValue").value; |
|
//console.log(column4); |
|
|
|
var normvar = document.getElementById("norm").value; |
|
var normunit = document.getElementById("nunit").value; |
|
var normratio = 1; |
|
|
|
d3.tsv("yogurt.tsv", function(error, data){ |
|
if (column4 == ""){ |
|
|
|
datatable.push([column0, column1, column2, column3]); |
|
data.forEach(function(d){ |
|
|
|
if(normvar != ""){normratio =normunit / +d[normvar];} |
|
datatable.push([d[column0], Math.round(+d[column1] * normratio), Math.round(+d[column2] * normratio), d[column3]]); |
|
}); |
|
|
|
} else { |
|
datatable.push([column0, column1, column2, column3, column4]); |
|
data.forEach(function(d){ |
|
if(normvar != ""){normratio =normunit / +d[normvar];} |
|
if (d[column4]>= 0) { |
|
|
|
datatable.push([d[column0], Math.round(+d[column1] * normratio), Math.round(+d[column2] * normratio), d[column3], Math.round(+d[column4] * normratio)]); |
|
} else { |
|
datatable.push([d[column0], Math.round(+d[column1] * normratio), Math.round(+d[column2] * normratio), d[column3], 0]); |
|
} |
|
|
|
}); |
|
} |
|
|
|
//console.log(datatable); |
|
|
|
}); |
|
} |
|
|
|
function drawChart(){ |
|
|
|
var data = new Array(); |
|
data = google.visualization.arrayToDataTable(datatable); |
|
|
|
//console.log(data); |
|
var graphtitle = document.getElementById("yValue").value; |
|
var hAxistitle = document.getElementById("xValue").value; |
|
var vAxistitle = document.getElementById("yValue").value; |
|
|
|
var options = { |
|
title: graphtitle, |
|
hAxis: {title: hAxistitle, viewWindowMode: "pretty"}, |
|
vAxis: {title: vAxistitle, viewWindowMode: "pretty"}, |
|
bubble: {textStyle:{fontSize: 12}} |
|
}; |
|
var chart = new google.visualization.BubbleChart(document.getElementById('chart_div')); |
|
chart.draw(data, options); |
|
|
|
} |
|
|
|
</script> |
|
</body> |
|
</html> |