Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change margins and padding in nvd3 chart

I have the following nvd3 stacked Area Chart:

enter image description here

I want to add margin between the numbers/dates and the graph as well as the legend at the top and the graph. (please see the picture, I've marked the positions with a red line:

enter image description hereenter image description here

I've been investigating the rendered html but can't access the margin values via css, even if I try it inline with firefox's console. I've been able to change font-family and color with this css:

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

But still whatever element (text,g,svg,...) I'm trying to attach a style to, nothing in terms of margin is changing.

Here's the javascript code for the chart:

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

I've been reading all over nvd3's examples and docs, but still can't find a way to manipulate above said. Does somebody know of a way to do?

like image 302
baao Avatar asked Apr 19 '15 21:04

baao


1 Answers

.nvd3 .nv-axis.nv-x path.domain {
  stroke-opacity: 1;
  stroke: red;
}

CSS is probably the way to go. (NVD3 makes the x-axis invisible by default, so you first want to set its opacity to 1.)

Example in this Plunker.

like image 137
Lucas Avatar answered Sep 23 '22 03:09

Lucas