jqplot: elements of stacked bar chart missing

。_饼干妹妹 提交于 2020-01-05 06:38:24

问题


I've been struggeling with the following for quite some time now.. Hopefully someone can help me out.

What I'm trying to do: Using jqplot I'm trying to combine a horizontal stacked bar chart with a line chart. The stacked bar chart should contain five values. The line chart should cross the stacked bar chart.

What I've come up with so far: I've managed to build the horizontal stacked bar chart and the line crosses it as it should.

The problem: My stacked bar chart now shows three blocks (values: 1, 4 and 16). I should be seeing five blocks (values: 1, 2, 4, 8 and 16).

The code I've used:

<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>  

Many thanks for any help you could offer!


回答1:


You need to apply CategoryAxisRenderer to yaxis (not to xaxis ) :

yaxis: {
   renderer: $.jqplot.CategoryAxisRenderer
}

See working example here

Edit : Add xaxis:{min:0} to axes options if you want to bound xaxis



来源:https://stackoverflow.com/questions/15473949/jqplot-elements-of-stacked-bar-chart-missing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!