Created
February 20, 2015 15:12
-
-
Save chsh/5c2f4fd232da49f154dc to your computer and use it in GitHub Desktop.
Draw barcode using d3.
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
//= require d3 | |
var height = 500; | |
var width = 800; | |
var margin_left = 20; | |
var xdim = 2; | |
var svgContianer = d3.select("body") | |
.append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
// data for 123456789012345 | |
var data = [ | |
[0, 2], [3, 1], [6, 3], [11, 1], [13, 2], [17, 3], [22, 1], [26, 1], [28, 2], [33, 3], [39, 1], [41, 2], [44, 2], [50, 1], [52, 1], [55, 2], [58, 4], [63, 2], [66, 1], [68, 2], [72, 3], [77, 1], [81, 1], [83, 2], [88, 1], [90, 4], [95, 3], [99, 2], [102, 3], [107, 1], [110, 1], [112, 3], [116, 2], [121, 2], [126, 3], [130, 1], [132, 2] | |
]; | |
var line = svgContianer.selectAll("line") | |
.data(data) | |
.enter() | |
.append("rect") | |
.attr("x", function (d, i) { | |
return margin_left + d[0] * xdim; | |
}) | |
.attr("width", function (d, i) { | |
return d[1] * xdim; | |
}) | |
.attr("y", 0) | |
.attr("height", 80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment