Skip to content

Instantly share code, notes, and snippets.

@vjpgo
Created February 1, 2013 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjpgo/4692180 to your computer and use it in GitHub Desktop.
Save vjpgo/4692180 to your computer and use it in GitHub Desktop.
Simple multi-line chart2
{"description":"Simple multi-line chart2","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"myData3.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.5128760529482547,"hidepanel":false}
//d3.csv("myData3.csv", function(data) {
var data = tributary.myData3;
data.forEach(function(d) {
d.date = new Date(d.date);
d.close = +d.close; // 1st line data
d.open = +d.open; // 2nd line data
});
// Find the extent
var dateExtent = d3.extent(data.map(function(d, i){return d.date;}));
var trendExtent = d3.extent(data.map(function(d, i){return d.open;}));
var w = 960;
var h = 400;
var pad = 73;
var x = d3.time.scale() .domain(dateExtent).range([0,w]);
var y = d3.scale.linear().domain(trendExtent).range([h,0]);
var svg = d3.select("svg").attr("height", h + pad).attr("width", w + pad);
var vis = svg.append("g").attr("transform", "translate(40,20)");
var lineGenerator = d3.svg.line()
.x(function(d) { console.log(1, d);return x(d.date); })
.y(function(d) { return y(d.open); })
.interpolate("basis");
var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(4).tickSubdivide(8).tickSize(-h, -h, -h).tickFormat(d3.time.format("%m/%d/%Y"));
var yAxis = d3.svg.axis().scale(y).orient("left").ticks(6).tickSubdivide(5).tickSize(-w, -w, -w);
var axisX = vis.append("g").classed("labels x_labels", true)
.attr("class", "x axis")
.attr("transform", "translate(0,"+h+")")
.call(xAxis);
vis.append("g").classed("labels y_labels", true)
.attr("class", "y axis")
.call(yAxis);
vis.append("path")
.data([data])
.attr("d", lineGenerator)
.attr("class", "line");
//});
date close open
2013-01-13 5.98 6
2013-06-13 3 4
2013-08-13 10.98 8
2013-10-13 12 10
2013-11-13 15 11
2013-12-3 18 13
2013-12-13 8 12
2013-12-23 6 10
path.line {
fill: none;
stroke: purple;
stroke-width: 1.5;
}
path.area {
fill: #E2B2B2;
}
.x.axis line {
stroke: green;
stroke-width: 1.5px;
}
.x.axis .minor {
stroke-opacity: .5;
stroke: red;
stroke-width: 0.5px;
}
.x.axis path {
fill: none;
stroke: #000000;
stroke-width: 1.0px;
}
.y.axis path {
fill: none;
stroke: #000000;
stroke-width: 1.0px;
}
.y.axis line {
fill: none;
stroke: #17BED5;
stroke-width: 0.81949;
}
.y.axis .minor{
stroke: #52D12A;
stroke-width: 0.5px;
stroke-opacity: 0.5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment