Horizontal stacked bar chart with negative values

1,171 views
Skip to first unread message

bmacquet

unread,
Oct 26, 2011, 3:34:45 PM10/26/11
to jqplot...@googlegroups.com
Hi,

Is it possible to draw horizontal stacked bar chart with negative values ?
I try to reproduce the attached graph built with Google Visualization.
(negative values stack from right to left and positive values stack from left to right)

I've tried to adapt code from "barTest" example, but it doesn't work as expected ;)

Thanks in advance for your help,

BMA
graph.png

bmacquet

unread,
Oct 27, 2011, 8:02:18 AM10/27/11
to jqplot...@googlegroups.com
I've tried this code :

$(document).ready(function(){
              var ticks = ['A', 'B', 'C'];
          plot4 = $.jqplot('chart4',
                                [
                                   [[-60,1], [5,2], [10,3]],
                                   [[10,1], [10,2], [20,3]],
                                   [[20,1], [15,2], [30,3]],
                                ], {
            stackSeries: true,
            captureRightClick: false,
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                //shadowAngle: 135,
                rendererOptions: {
                    barDirection: 'horizontal',
                    highlightMouseOver: true 
                },
                pointLabels: {show: true, formatString: '%d'},
                fillToZero: true,
                fillAxis: 'x',
                useNegativeColors: true,
                shadow: false
            },
            series:[
                    {label:'Event 1', color: 'black'},
                    {label:'Event 2', color: 'green'},
                    {label:'Event 3', color: 'blue'},
            ],
            legend: {
                show: true,
                location: 'e',
                placement: 'outside'
            },
            axes: {
                yaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    ticks: ticks
                },
            }
        });
    });

Everything is fine if "stackSeries" is false (see attached image "Bar-OK") but i don't figure out why with "stackSeries: true", all values of the first serie are negative (see attached image "Bar-KO")

Any ideas ? Maybe it's a bug ?

Thanks,

BMA
Bar-KO.png
Bar-OK.png

bmacquet

unread,
Nov 4, 2011, 11:02:07 AM11/4/11
to jqplot...@googlegroups.com
Can someone point me in right direction ?

Any help would be greatly appreciated,

Thanks,

BMA


Miquel Rodríguez Telep

unread,
Nov 25, 2011, 8:56:13 AM11/25/11
to jqplot...@googlegroups.com
Hi BMA,

I'm having the same issue. I've looked into it and it seems that this happens because, regardless of the fillToZero settings, jqPlot always plots subsequent bars starting from the previous data point. So, if you have a data point at -200 and fillToZero is true, it will be plotted from 0 to -200. If the next data point is 100, then it will be plotted from -200 (the previous point) up to 100.

There is an issue report about this, and I've just written a reply where I've tried to explain my understanding of how jqPlot handles plotting bars and how I think it could be improved. Maybe discussion should be directed there: https://bitbucket.org/cleonello/jqplot/issue/181/nagative-values-in-stacked-bar-chart#comment-814705

bmacquet

unread,
Nov 29, 2011, 3:38:19 AM11/29/11
to jqplot...@googlegroups.com
Thank you Miquel.

I'll follow the discussion in bitbucket.

BMA
Reply all
Reply to author
Forward
0 new messages