gpt4 book ai didi

javascript - 更改 nvd3 图表中的边距和填充

转载 作者:可可西里 更新时间:2023-11-01 02:36:19 24 4
gpt4 key购买 nike

我有以下 nvd3 堆积面积图:

enter image description here

我想在数字/日期和图表以及顶部的图例和图表之间添加边距。 (请看图,我用红线标出了位置:

enter image description here enter image description here

我一直在研究呈现的 html 但无法通过 css 访问边距值,即使我尝试将其与 firefox 的控制台内联。我已经能够使用此 css 更改字体系列和颜色:

#chart1
height: 300px
text
fill: #1a1f22
font-size: 0.7em
font-family: 'Source Sans Pro', sans-serif

但是无论我尝试将样式附加到什么元素(文本、g、svg 等),边距方面都没有任何变化。

这是图表的 javascript 代码:

nv.addGraph(function() {
var histcatexplong = [
<?= $array ?>

];


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

var chart;
chart = nv.models.stackedAreaChart()
.useInteractiveGuideline(true)
.showControls(false)
.x(function(d) { return d[0] })
.y(function(d) { return d[1] })
.color(keyColor)

.transitionDuration(300);




chart.xAxis
.tickFormat(function(d) { return d3.time.format('%e.%m.%y')(new Date(d)) });



chart.yAxis
.tickFormat(d3.format(',.2f'));

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;
});

我一直在阅读 nvd3 的所有示例和文档,但仍然找不到一种方法来操作上面所说的。有人知道怎么做吗?

最佳答案

关于您的 margin 问题,您可以通过调用更改图例周围的 margin :

 chart.legend.margin().bottom = 50;

或者:

 chart.legend.margin({top: 5, right: 0, bottom: 50, left: 0});

您可以使用常规 D3 tickPadding function 在刻度线和轴之间添加空间:

 chart.yAxis.tickPadding(25);
chart.xAxis.tickPadding(25);

喜欢this Plunker .

关于javascript - 更改 nvd3 图表中的边距和填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29736374/

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