Pracuję nad prostym przykładem wykresu kołowego przy użyciu NVD3. Wykonuje renderowanie poprawnie, ale nie reaguje. Próbowałem podążać za numerem this answer, aby był responsywny, ale nie do końca do niego dotarłem.Responsywny wykres kołowy za pomocą NVD3
Zrobiłem fiddle. Rzeczywiście, jest responsywny, ale nie jestem w stanie dopasować wykresu do kontenera. Mój kod js:
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.showLabels(true);
var $container = $('#chart'),
width = $container.width(),
height = $container.height();
d3.select("#chart svg")
.attr("width", '100%')
.attr("height", '100%')
.attr('viewBox','0 0 '+Math.min(width,height)+' '+Math.min(width,height))
.attr('preserveAspectRatio','xMinYMin')
.attr("transform", "translate(" + Math.min(width,height)/2 + "," + Math.min(width,height)/2 + ")")
.datum(exampleData)
.transition().duration(350)
.call(chart);
return chart;
});
var exampleData = [
{
"label": "One",
"value" : 29.765957771107
} ,
{
"label": "Two",
"value" : 0
} ,
{
"label": "Three",
"value" : 32.807804682612
} ,
{
"label": "Four",
"value" : 196.45946739256
} ,
{
"label": "Five",
"value" : 0.19434030906893
} ,
{
"label": "Six",
"value" : 98.079782601442
} ,
{
"label": "Seven",
"value" : 13.925743130903
} ,
{
"label": "Eight",
"value" : 5.1387322875705
}
];
Jak mogę prawidłowo dopasować wykres do jednostki div o wielkości procentowej?
można zobaczyć, że iloczyn viewBox przypisuje się o 2 lub 3, wielkość tabeli zmniejsza, ale zależy to od procentowa div także, więc to nie jest całkiem pomocne. – daao87