本文整理匯總了TypeScript中d3.csv函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript csv函數的具體用法?TypeScript csv怎麽用?TypeScript csv使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了csv函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: line
graph.append("svg:g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// create left yAxis
let yAxisLeft = d3.svg.axis().scale(y).ticks(4).orient("left");
// Add the y-axis to the left
graph.append("svg:g")
.attr("class", "y axis")
.attr("transform", "translate(-25,0)")
.call(yAxisLeft);
// Add the line by appending an svg:path element with the data line
// we created above do this AFTER the axes above so that the line is
// above the tick-lines
graph.append("svg:path").attr("d", line(data_row));
}
let current_graph:number = 1;
d3.csv("data/cp_executed.csv", function(data){
for (let i in data) {
let actual_data:number[] = [];
for (let j in years) {
actual_data.push(parseInt(data[i][j]))
}
GenerateGraph(data[i], current_graph);
current_graph++;
}
});
示例2: StackedLineChart
document.addEventListener('DOMContentLoaded', ()=> {
let chart = new StackedLineChart({
height: 300,
target: document.getElementById('chart'),
});
d3.csv("./output.csv")
.get(function (error, rows) {
let dataGroups:ChartData[] = [
new ChartData('acceleration', []),
new ChartData('x', []),
new ChartData('y', []),
new ChartData('z', [])
],
xAxisData:any[] = [];
var seconds = 0,
prevValue, prevMilliSecond;
debugger;
rows.forEach((row:any)=> {
var accelerate = parseFloat(row.acceleration),
x = parseFloat(row.x),
y = parseFloat(row.y),
z = parseFloat(row.z),
milliSecond;
if (x === 0 && y === 0 && z === 0) {
return;
}
xAxisData.push(new Date(row.date));
dataGroups[0].push(accelerate);
dataGroups[1].push(x);
dataGroups[2].push(y);
dataGroups[3].push(z);
});
chart.render(xAxisData, dataGroups);
// setTimeout(()=>{
// const SLICE_NUM = 30;
//
// let newGroupData = [
// new ChartData('acceleration', []),
// new ChartData('x', []),
// new ChartData('y', []),
// new ChartData('z', [])
// ];
//
// newGroupData[0].data = dataGroups[0].data.slice(0, SLICE_NUM);
// newGroupData[1].data = dataGroups[1].data.slice(0, SLICE_NUM);
// newGroupData[2].data = dataGroups[2].data.slice(0, SLICE_NUM);
// newGroupData[3].data = dataGroups[3].data.slice(0, SLICE_NUM);
// debugger;
// chart.updateData(xAxisData.slice(0, SLICE_NUM), newGroupData);
// }, 4000 )
});
});
示例3: line
data_row = data_row_temp;
// Add the line by appending an svg:path element with the data line
// we created above do this AFTER the axes above so that the line is
// above the tick-lines
graph.append("svg:path").data(data_row).attr("d", line(data_row));
// Add the jurisdiciton
graph.append("svg:text")
.attr("x", (width / 2))
.attr("y", 0 - (margins[1] / 2))
.attr("text-anchor", "middle")
.style("font-size", "16px")
.style("text-decoration", "underline")
.text(title);
console.log(title)
}
let current_graph:number = 1;
d3.csv("data/cp_executed.csv", function(data){
for (let i in data) {
let actual_data:number[] = [];
let data_row = data[i];
for (let j of years) {
actual_data.push(+data_row[j]);
}
GenerateGraph(data[i]["Jurisdiction"], actual_data, current_graph);
current_graph++;
}
});
示例4: ngOnInit
ngOnInit(){
var el = this.elementRef.nativeElement;
var attrName = el.children && el.children[0] && el.children[0].attributes && el.children[0].attributes[0] && el.children[0].attributes[0].name;
var componentContainer = d3.select(this.elementRef.nativeElement);
var d3Container = componentContainer.select("#display");
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.rangeRound([height, 0]);
var color = d3.scale.ordinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(d3.format(".2s"));
var svg = d3Container
.append("svg")
.attr(attrName, "")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr(attrName, "")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("app/components/bar-charts-stacked-bar-chart/data.tsv", function(error, data) {
if (error) throw error;
color.domain(d3.keys(data[0]).filter(function(key) { return key !== "State"; }));
data.forEach(function(d) {
var y0 = 0;
d.ages = color.domain().map(function(name) { return {name: name, y0: y0, y1: y0 += +d[name]}; });
d.total = d.ages[d.ages.length - 1].y1;
});
data.sort(function(a, b) { return b.total - a.total; });
x.domain(data.map(function(d) { return d.State; }));
y.domain([0, d3.max(data, function(d) { return d.total; })]);
svg.append("g")
.attr(attrName, "")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr(attrName, "")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr(attrName, "")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Population");
var state = svg.selectAll(".state")
.data(data)
.enter().append("g")
.attr(attrName, "")
.attr("class", "g")
.attr("transform", function(d) { return "translate(" + x(d.State) + ",0)"; });
state.selectAll("rect")
.attr(attrName, "")
.data(function(d) { return d.ages; })
.enter().append("rect")
.attr(attrName, "")
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.style("fill", function(d) { return color(d.name); });
var legend = svg.selectAll(".legend")
.data(color.domain().slice().reverse())
.enter().append("g")
.attr(attrName, "")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
legend.append("rect")
.attr(attrName, "")
//.........這裏部分代碼省略.........
示例5: require
declare const require: Function
const d3 = require('d3')
import measureFPS = require('../../measure')
import common = require('../common')
let resize: any = { interval: 60 }
d3
.csv('ny-vs-sf.csv')
.row((d: any) => ({
NY: parseFloat(d.NY.split(';')[0]),
SF: parseFloat(d.SF.split(';')[0])
}))
.get((error: any, data: any) => {
if (error != null) alert('Data can\'t be downloaded or parsed')
else {
common.drawCharts(data)
resize.request = function() {
resize.timer && clearTimeout(resize.timer)
resize.timer = setTimeout(resize.eval, resize.interval)
}
resize.eval = function() {
d3.selectAll('svg').remove()
d3.select('.charts').selectAll('div').append('svg')
common.drawCharts(data)
}
window.addEventListener('resize', resize.request, false)
}
})
measureFPS.measure(3, function (fps: any) {
示例6:
import * as d3 from "d3";
d3.csv('resources/cars.csv', (data) => {
console.log(data);
})