NVD3 Charts Remove 0 Value Databases

For NVID3 multiBarChart, how can you remove null-value bars? I tried to set the y value to null, but they will not disappear.

Unfortunately, I do not have enough reputation to post the image, so here ascii shows the problem. The following ascii diagram has two multi-line diagrams, X and Z, with underscores (_) representing zero characters in the Z series:

| | _ | _ X | _ XXX | _ XXXXX | XXXXXX ZZ Z 

I need the following:

 | | | X | XXX | XXXXX | XXXXXX ZZ Z 

Edit: here is the JSFiddle for the chart http://jsfiddle.net/dnn4K/1/

I included an attempt to fix mine, which works somewhat (but not in the violin for some reason). Trying to fix finds the first rectangle through the CSS selector and iterates through it with rect.next (), setting the height to 0 if the height is 1. The reason this doesn't work for me is because the rectangles don't exist at the time calling the function - so now I need to figure out how to get the function to start after the animation finishes.

+8
source share
2 answers

In fact, I found that having to modify the nvd3 source code is not a real solution.

So, I just added an overriding CSS rule that hides any flat height of 1 pixel.

Still not optimal, but we will have to wait for the new version of nvd3, hopefully a fully customizable model, to do it right.

 .nvd3 rect[height="1"] { display: none !important; } 
+20
source share

Finding out the answer. The nv.d3.js file contains the following line of code:

 .attr('height', function(d,i) { return Math.max(Math.abs(y(dy + (stacked ? d.y0 : 0)) - y((stacked ? d.y0 : 0))),1); //Min value of stacked bar charts set here }) 

This needs to be changed to the following:

 .attr('height', function(d,i) { return Math.max(Math.abs(y(dy + (stacked ? d.y0 : 0)) - y((stacked ? d.y0 : 0))),0); //Min value of stacked bar charts set here }) 

What is it. The value of min is simply set to 1 instead of 0 for stacked histograms. It was in the multiBar function of nv.d3.js on line 7804. Hope this helps someone else with the same problem.

+3
source share

All Articles