gpt4 book ai didi

javascript - NVD3 图表响应问题

转载 作者:行者123 更新时间:2023-11-30 12:12:13 25 4
gpt4 key购买 nike

NVD3响应问题

我有第二页的代码,我在其中使用了与此处完全相同的图表。但是在那个页面上它是响应式的,我试图弄清楚为什么图表在这里没有响应式。

enter image description here

  var colors = ["rgba(74, 210, 255, .8)", "rgba(85, 172, 238, .8)", "rgba(205, 32, 31, .8)"];
d3.scale.colors = function() {
return d3.scale.ordinal().range(colors);
};

var colors = d3.scale.colors();
/*var colors = d3.scale.category20();*/
var keyColor = function(d, i) {return colors(d.key)};

var chart;
nv.addGraph(function() {
chart = nv.models.stackedAreaChart()
.useInteractiveGuideline(true)
.x(function(d) { return d[0] })
.y(function(d) { return d[1] })
.showControls(false)
.showYAxis(true)
.showLegend(false)
.rightAlignYAxis(true)
.controlLabels({stacked: "Stacked"})
.color(keyColor)
.duration(500);

chart.xAxis.tickFormat(function(d) { return d3.time.format('%a')(new Date(d)) });
chart.yAxis.tickFormat(d3.format('f'));

chart.legend.margin({
top: 30
});

d3.select('#chart1')
.datum(histcatexplong)
.transition().duration(1000)
.call(chart)
.each('start', function() {
setTimeout(function() {
d3.selectAll('#chart1 *').each(function() {
if(this.__transition__)
this.__transition__.duration = 1;
})
}, 0)
});

nv.utils.windowResize(chart.update);
return chart;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

<div class="slide1">
<div class="col-xs-12" id="margin-chart">
<svg id="chart1" style="width: 100%; height: 300px;"></svg>
</div>
</div>

最佳答案

当您的 slideToggle 函数完成时,您需要调用 chart.update() 以使 nvd3 将图表重绘到新的尺寸。

即:

$('#chart').slideToggle(function() {
chart.update();
});

关于javascript - NVD3 图表响应问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33445128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com