I'm trying to draw multiple graphs in one svg image, based on chromosomal data. The purpose is to draw 1 graph per chromosome. I want to transpose the axis (and the data) based on the chromosome number in de data.
Data entries look like this (in JSON):
[{ "chrom": 1, "pos": 2000000, "ratio": 0.0253, "average": 0.0408, "stdev": 0.0257, "z-score": - 0.6021 }, { "chrom": 1, "pos": 2250000, "ratio": 0.0304, "average": 0.0452, "stdev": 0.0245, "z-score": - 0.6021 }, { "chrom": 1, "pos": 2500000, "ratio": 0.0357, "average": 0.0498, "stdev": 0.024, "z-score": - 0.5885 }, { "chrom": 1, "pos": 2750000, "ratio": 0.0381, "average": 0.0522, "stdev": 0.0228, "z-score": - 0.6146 }, {etc..}
Currently my code looks like this:
d3.json("data.json", function(error, data) { if (error) throw error; x.domain(d3.extent(data, function(d) { return d.pos; })); y.domain(d3.extent(data, function(d) { return d['ratio']; })); svg.append("g") .attr("class", "x axis") .data(data) //.attr("transform", "translate(0," + graph_height + ")") .attr('transform', function(d) { if (d.chrom > Math.ceil(chrnumber / 2)) { console.log('translate('+ graph_width + graph_margin.center + ',' + graph_height + d.chrom * (graph_height + graph_margin.top) + ')'); return 'translate('+ graph_width + graph_margin.center + ',' + graph_height + d.chrom * (graph_height + graph_margin.top) + ')'; }else { console.log('translate(0,' + graph_height + d.chrom * (graph_height + graph_margin.top) + ')'); return 'translate(0,' + graph_height + d.chrom * (graph_height + graph_margin.top) + ')'; } }) .call(xAxis); });
But this yields no errors, nor any output. I suppose there is some kind of error in the code above, because the svg image isn't generated on the page.
Does anyone have an idea where I went wrong?