【问题标题】:jqplot: elements of stacked bar chart missingjqplot:堆积条形图的元素丢失
【发布时间】:2013-03-18 09:58:30
【问题描述】:

我一直在努力解决以下问题。希望有人可以帮助我。

我正在尝试做的事情: 使用 jqplot 我试图将水平堆积条形图与折线图结合起来。堆积条形图应包含五个值。折线图应穿过堆积条形图。

到目前为止我的想法: 我已经设法构建了水平堆积条形图,并且线条应该穿过它。

问题: 我的堆叠条形图现在显示三个块(值:1、4 和 16)。我应该看到五个块(值:1、2、4、8 和 16)。

我用过的代码:

<script type="text/javascript">

    $(document).ready(function() {
        var x1 = [[1,1]];
        var x2 = [[2,1]];
        var x3 = [[4,1]];
        var x4 = [[8,1]];
        var x5 = [[16,1]];
        var x6 = [[1,0.5],[1,1.5]];

        var plot2 = $.jqplot('thema1chart', [x1, x2, x3, x4, x5, x6], {
            stackSeries: true,
            seriesDefaults: {
                renderer: $.jqplot.BarRenderer,
                rendererOptions: {
                    barDirection: 'horizontal'
                },
                pointLabels: {
                    show: false,
                    stackedValue: true
                }
            },
            series: [{shadow: false, color:'#666666'},
            {shadow: false, color:'#FFFFFF'},{shadow: false, color:'#b4d2dd'},{shadow: false, color:'#FFFFFF'},{shadow: false, color:'#666666'},
                     { 
                     shadow: false,
                         disableStack : true,//otherwise it wil be added to values of previous series
                renderer: $.jqplot.LineRenderer,
                lineWidth: 2,
                label:'Benchmark',
                color:'#666666',
                showLine:false, 
                pointLabels: {
                    show: false
                },
                markerOptions: {
                    size: 7, style:"plus" 
                }}],
            axes: {
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer
                }
                ,
                yaxis: {
                    autoscale: true
                }
            }
        });
    });
    </script>  

非常感谢您提供的任何帮助!

【问题讨论】:

    标签: jqplot stacked


    【解决方案1】:

    您需要将 CategoryAxisRenderer 应用于 yaxis(而不是 xaxis ):

    yaxis: {
       renderer: $.jqplot.CategoryAxisRenderer
    }
    

    working example here

    编辑:如果要绑定 xaxis,请将 xaxis:{min:0} 添加到轴选项

    【讨论】:

    • 嗨安东尼,非常感谢!你的回答正是我所需要的!
    猜你喜欢
    • 2015-01-04
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    相关资源
    最近更新 更多