Negative values and positive values on a stacked bar draw by relative position. #229

Open
jimdrewes opened this Issue Apr 11, 2013 · 5 comments

Comments

Projects
None yet
5 participants

If you have a stacked bar chart with positive values in one series, and negative values in the next series, the negative values will start to draw starting at the top of the positive bar, then going down. The only way I've found to start drawing the negative starting at zero, is to pass an inverse series of data, like so:

   $(document).ready(function () {
        graph = new Rickshaw.Graph({
            element: document.querySelector("#burndowngraph"),
            renderer: 'bar',
            min: 'auto',
            series: [{
                color: 'white',
                data: [
                    { x: 0, y: 100 },
                    { x: 1, y: 90 },
                    { x: 2, y: 75 },
                    { x: 3, y: 65 },
                    { x: 4, y: 58 },
                    { x: 5, y: 50 },
                    { x: 6, y: 40 },
                    { x: 7, y: 25 },
                    { x: 8, y: 5 },
                    { x: 9, y: 2 }]
            }, {
                color: 'white',
                data: [
                    { x: 0, y: -100 },
                    { x: 1, y: -90 },
                    { x: 2, y: -75 },
                    { x: 3, y: -65 },
                    { x: 4, y: -58 },
                    { x: 5, y: -50 },
                    { x: 6, y: -40 },
                    { x: 7, y: -25 },
                    { x: 8, y: -5 },
                    { x: 9, y: -2 }]
            }, {
                color: 'red',
                data: [
                    { x: 0, y: 0 },
                    { x: 1, y: 0 },
                    { x: 2, y: 0 },
                    { x: 3, y: 0 },
                    { x: 4, y: -5 },
                    { x: 5, y: -5 },
                    { x: 6, y: -3 },
                    { x: 7, y: -1 },
                    { x: 8, y: 0 },
                    { x: 9, y: 0 }]
            }]
        });
Contributor

dchester commented Apr 16, 2013

This is a problem worth solving. Thanks for the example graph.

Just wondering if anyone has started work on this? I need to solve this as well and have some time up my sleeve next week.

Contributor

dchester commented Aug 2, 2013

I don't think we've put much time in on this issue yet.

At a glance, we may need to specify our own offset function when we call the stacker from d3.layout.stack(). We'd welcome the help if you have some time to investigate.

pepijn commented Jul 24, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment