I've created a musical waveform using D3 by positioning rectangles next to each other. Check out the code here: http://jsfiddle.net/s4dML/
var data = [ 0.0534973, /* ...lots and lots of data... */ 0.290771];
data = data.filter(function(datum, index){
return index % 3 == 0;
});
var width = 340,
height = 70,
svg = d3
.select('body')
.append('svg')
.attr('width', width)
.attr('height', height);
svg
.selectAll('rect')
.data(data.map(function(datum){
return (datum * height)/2;
}))
// .data(dataset)
.enter()
.append('rect')
.attr('x', function(d, i){
return i * (width / data.length);
})
.attr('y', function(d){
return (height /2) - d ;
})
.attr('width', function(d, i){
return width / data.length;
})
.attr('height', function(d){
return d*2;
})
.attr('fill', 'teal');
Can anyone explain why my waveform isn't a uniform color as I expected? It seems to have a shimmering effect which may be intentional, but I'd like to understand how it happened and how to remove it if needed.