-
-
Save bengolder/9139521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF8"> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="tosci.js" charset="utf-8"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseRow(d) { | |
var dateTimeJoiner = d3.time.format("%x %X") // combines date and time into a Date object | |
var dateTime = dateTimeJoiner.parse(d["Date"] + " " + d["Time"]) // grabs the date and time | |
var gross_sales_conversion = +d["Gross Sales"].substr(1) //strips the $ sign | |
var total_sales = gross_sales_conversion * 1.07 //add tax | |
return { | |
date: dateTime, | |
category: d.Category, | |
item: d.Item, | |
quantity: +d.Quantity, | |
pricepoint: d["Price Point Name"], | |
gross_sales: gross_sales_conversion, | |
total_sale: +d3.format(".2f")(total_sales), // rounds to 2 decimal places | |
device_name: d["Device Name"] | |
}; | |
} | |
function handleRows( error, rows ) { | |
// this function is only called once all the rows are loaded | |
// In this function you can now access the loaded and parsed rows | |
rows.forEach( handleRow ); | |
console.log("dataset after loading csv:", dataset) | |
} | |
function handleRow( row, i, rows ) { | |
console.log("item #", i, row.date, "adding to dataset"); | |
dataset.push(row); | |
} | |
// d3.csv( csv_file_path, parsing_function, callback_function) | |
d3.csv("5feb2014.csv", parseRow, handleRows); | |
var dataset = []; | |
console.log("dataset before loading csv:", dataset) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment