本文整理匯總了TypeScript中d3-request.csv函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript csv函數的具體用法?TypeScript csv怎麽用?TypeScript csv使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了csv函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: onCsv
function onCsv(f: (csv: [number, number][]) => void) : void {
csv('ny-vs-sf.csv')
.row((d: {NY: string, SF: string}) => [
parseFloat(d.NY.split(';')[0]),
parseFloat(d.SF.split(';')[0]),
])
.get((error: null, data: [number, number][]) => {
if (error != null) {
alert('Data can\'t be downloaded or parsed')
return
}
f(data)
})
}
示例2: function
// -------------------------------------------------------------------------------
const xml: d3Request.Request = d3Request.xml(url);
const xmlWithCallback: d3Request.Request = d3Request.xml(url, function(error, data) {
const that: d3Request.Request = this;
const err: any = error;
const d: any = data;
console.log(d);
});
// -------------------------------------------------------------------------------
// CSV Request
// -------------------------------------------------------------------------------
// url only
let csvRequest: d3Request.DsvRequest = d3Request.csv(url);
// url and callback for response handling
const csvRequestWithCallback: d3Request.DsvRequest = d3Request.csv(url, function(error, data) {
const that: d3Request.Request = this;
const err: any = error;
const d: DSVParsedArray<DSVRowString> = data;
console.log(d);
});
// url, row mapping function and callback for response handling
const csvRequestWithRowWithCallback: d3Request.DsvRequest = d3Request.csv<ResponseDatumGET>(url,
(rawRow, index, columns) => {
const rr: DSVRowString = rawRow;
const i: number = index;
const cols: string[] = columns;
示例3: require
ďťżdeclare const require: Function
const d3request = require('d3-request')
const d3shape = require('d3-shape')
const d3selection = require('d3-selection')
import measureFPS = require('../../measure')
import draw = require('./draw')
import drawModelCS = require('./drawModelCS')
const startDate = new Date()
d3request
.csv('ny-vs-sf.csv')
.row((d: any) => [
parseFloat(d.NY.split(';')[0]),
parseFloat(d.SF.split(';')[0])
])
.get((error: any, data: any[]) => {
if (error != null)
{
alert('Data can\'t be downloaded or parsed')
return
}
const onPath = (path: any) => {
path.attr('d', (cityIdx: number) =>
d3shape.line()
.defined((d: number[]) => d[cityIdx])
.x((d: number[], i: number) => i)
.y((d: number[]) => d[cityIdx])
.call(null, data)
)
}