Ciao a tutti, sto cercando di usare la libreria Javascript D3 per creare dei grafici che vorrei si aggiornassero in base ai dati che ho nel mio database. LAvoro in .net mvc5, mi sono creato il mio controller nel quale ho messo la query per andare a prendere i dati, e nell'index.cshtml ho scritto il javascript per costruire il grafico.

Mi costruisce gli assi x e y, mi prendere correttamente i dati dal db attraverso la mia query ma non mi disegna le barre nel grafico! questo è il js che ho scritto :


<script>


var margin = { top: 20, right: 20, bottom: 10, left: 40 },
width = 600 - margin.left - margin.right,
height = 300 - margin.top - margin.bottom;


var x = d3.scale.ordinal().rangeRoundBands([0, width], .05);


var y = d3.scale.linear().range([height, 0]);


var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")




var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10);

var svg = d3.select("#barchart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style('background', '#bce8f1')
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");



var chart = d3.json('@Url.Action("getChart", "Chart")', function (data) {








svg.append("g")
.attr("class", "xAxis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.style("text-anchor", "end")



svg.append("g")
.attr("class", "yAxis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")


svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.style("fill", "steelblue")
.attr("x", function (d) { return x(d.data); })
.attr("width", x.rangeBand())
.attr("y", function (d) { return y(d.data); })
.attr("height", function (d) { return height - y(d.value); });


x.domain(data.map(function (d) { return d.data; }));
y.domain([0, d3.max(data, function (d) { return d.data; })]);


data.forEach(function (d) {


d.close = +d.close;

});

});

</script>

Riuscite a capire perché non mi disegna le barre??