正確加載數據非常困難。這裏是標題行與第一內容行:在csv中讀取日期解析
BookingID,Type,Status,Unit Booked,Unit Owner,Destination,Booking Date,Checkin,Checkout,Renter - FirstName,Renter - LastName,Renter - EmailAddress,Renter - WorkPhone,Renter - HomePhone,#Adults,#Children,Total Stay,Total Paid,Total Due
15642889,House,Confirmed,GV T3 #2106,,,3/20/2016 7:00:00 PM,3/23/2016 3:00:00 PM,3/28/2016 11:00:00 AM,FirstName,LastName,first&[email protected],+1 (000) 000-0000,+1 (000) 000-0000,2,0,895,895,0
和加載並解析我的CSV我想要的相關線路:
var parseDate = d3.time.format("%m/%d/%Y %H:%M:%S %p").parse;
var data = d3.csv("Sales Export Friendly 3-19-17.csv", function(data) {
return {
unit: data["Unit Booked"],
date: parseDate(data["Booking Date"]).getMonth() + 1,
checkin: parseDate(data["Checkin"]).getMonth() + 1,
LOS: parseDate(data["Checkout"]).valueOf() - parseDate(data["Checkin"]).valueOf()/(24*60*60*1000),
total: +data["Total Stay"],
avgNight: (+data["Total Stay"])/((new Date(data["Checkout"]).valueOf() - new Date(data["Checkin"]).valueOf())/(24*60*60*1000))
};
});
的想法是,我會那麼做這樣的事情這個:
d3.parcoords()("#TopLeft").alpha(0.4)
.data(data)
.dimensions(data.columns)
如果我試着console.log(data.columns);在我的回調函數之後,我得到了undefined。這是什麼console.log(數據);版畫,這是相當奇怪的看着:
Object { header: Cn/u.header(), mimeType: Cn/u.mimeType(), responseType: Cn/u.responseType(), response: Cn/u.response(), get: Cn/</u[n](), post: Cn/</u[n](), send: Cn/u.send(), abort: Cn/u.abort(), on: M/<(), row: e/o.row() }
和錯誤代碼我目前得到:在d3.parcoords
TypeError: data.slice is not a function
當調用數據(數據)和
TypeError: e is undefined
在此行:
checkin: parseDate(data["Checkin"]).getMonth() + 1,
我是ter在這裏發生了什麼問題的肋骨混淆。我正在使用d3 v3。
我沒有用過D3的CSV解析器(雖然我使用D3否則) 。但是,如果您使用的是版本3,那麼您的數據結果看起來就像是完全數組,作爲第二個回調,而不是返回結果。您定義的唯一回調函數是訪問器。請參閱[文檔](https://github.com/d3/d3-3.x-api-reference/blob/master/CSV.md#csv) –