jqplot Side by Side Stacked Bar Chart

前端 未结 3 643
忘掉有多难
忘掉有多难 2021-01-12 01:08

Is it possible to achieve a side by side stacked bar chart using jqplot? For example the X-Axis would be a given month and for each month you would have some number of stac

3条回答
  •  日久生厌
    2021-01-12 01:29

    You will have to plot two graphs on same plot base which will be okay to do if you don't want any tool-tip or something because it will work on only one of the plot try this-

    $(document).ready(function(){
        /* graph config */
        var maxVal = 13;
    
        /* graph vals */
        var Bar1 = [5, 0, 10, 0, 12, 0];
        var Bar2 = [0, 17, 0, 20, 0, 12 ];
        var BaseVals=[0,0,0,0,0,0];
        /* graph ticks */
        var baseTicks=['Americas','','Europe','','Asia','']
        var EmptyTicks=['','','','','','']
    
    
        /* plot the base graph */
        plotbase = $.jqplot('chart3', [BaseVals], {
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                rendererOptions: {barMargin: 10},
                pointLabels: {show: false}
            },
            axesDefaults: {show: false}, 
            tickOptions: {showMark: false, angle: 90}, 
            axes: {
                showLabel: false, 
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer, 
                    ticks: baseTicks, 
                    tickOptions: {markSize: 0}
                }, 
                yaxis: {
                    padMin: 0, 
                    min: 0,
                    max: maxVal, 
                    showLabel: false, 
                    show: false
                }
            }
        }); 
    
    
    
    
    
        plot2 = $.jqplot('chart3', [Bar1], {
            seriesColors: ["#67ce64", "#da9831","#67ce64", "#da9831"],\\this can be changed 
            stackSeries: true,
            captureRightClick: true,
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                rendererOptions: {barMargin: 10, highlightMouseOver: true},
                pointLabels: {show: false}
            },
            axesDefaults: {show: false}, 
            tickOptions: {showMark: false}, 
            axes: {
                showLabel: false, 
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer, 
                    ticks: EmptyTicks
                },
                yaxis: {
                    padMin: 0, 
                    min: 0,
                    max: maxVal, 
                    showLabel: false, 
                    show: false
                }
            },
            grid: {background: 'transparent', drawGridLines: false, gridLineColor: 'transparent', borderColor: 'transparent'}
        });
    
    
        plot1 = $.jqplot('chart3', [Bar2], {
            stackSeries: true,
            captureRightClick: true,
            seriesColors: ["#effa38", "#37d1f8", "#5129b6","#5129b6"],//this can be changed 
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                rendererOptions: {barMargin: 10, highlightMouseOver: true },
                pointLabels: {show: false}
            },
            axes: {
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer, 
                    tickRenderer:$.jqplot.CanvasAxisTickRenderer,
                    ticks: EmptyTicks, 
                    tickOptions: {
                        angle: -90, 
                    }
                },
                yaxis: {
                    padMin: 0, 
                    min: 0,
                    max: maxVal
                }
            }, grid: {background: 'transparent', drawGridLines: false, gridLineColor: 'transparent', borderColor: 'transparent'}
        });
    
    });
    

    But note this that you will be able to apply tool-tip/Highlighter on only one of the plot

提交回复
热议问题