2017-02-09 41 views
1

我使用Primefaces 6爲我公司的圖表需求,它依賴於jQplot。 對於一個項目,我試圖覆蓋與負值的疊置條形圖上線圖,獲得這樣的事情:如何使用Primefaces jQplot實現禁用單個系列上的堆疊

Account Retention Visualisation

的問題是,當我嘗試一個linechartseries添加到與兩個barchartseries相同的模型,當在模型上設置setStacked(true);時,折線圖成爲堆棧的一部分,因爲Primefaces似乎不允許在系列上單獨禁用堆疊,僅限於每個模型。所以我結束了這個與

<p:chart type="bar" model="#{backingBean.cartesianChartModel}"/> 

Line Chart as part of the Stack

繪製圖表時經過一番調查我已經notoced是jQplot能夠禁止由JS選項傳遞disableStack : true堆積對個別系列的,所以問題是否可以通過PF或通過一些JS hack在渲染頁面上以某種方式覆蓋它?我覺得使用擴展器只有蘋果到整個模型?

相關的問題:Disable individual stacking

+0

_」我覺得使用擴展僅蘋果給整個模型?「_嘗試...看例子...不要預先得出結論。 – Kukeltje

回答

1

通過通過文檔澆我找到了一個解決問題的辦法,如果沒有這樣的問題:

似乎Primefaces允許個別系列從在堆棧中excempt在這個版本創建系列,通過

LineChartSeries.setDisableStack(true); 

這樣簡單。

+0

良好的調查,upvoted – Kukeltje

1

我想這可能是可能的。過去,我使用擴展功能來處理一些jqPlot攻擊。

在我的情況下,例如,我有一個擴展函數定義的圓環圖如下:

private void createDonutModel() { 
     donutModel = new DonutChartModel(); 
     donutModel.setLegendPosition("s"); 
     donutModel.setLegendPlacement(LegendPlacement.OUTSIDE); 
     donutModel.setSliceMargin(4); 
     donutModel.setDataFormat("value"); 
     donutModel.setShadow(false); 
     donutModel.setExtender("donutExtender"); 
     donutModel.setSeriesColors("B81C40, FFA600, 79B54A"); 
    } 

相應的JavaScript是做一些改變jqPlot:

/** 
* Customized jqPlot JQuery layout of the Donut Chart for Status Dashboard. 
*/ 
function donutExtender() { 
    this.cfg.seriesDefaults = { 
     // make this a donut chart. 
     renderer:$.jqplot.DonutRenderer, 
     rendererOptions:{   
      thickness: 26, 
      ringMargin: 0, 
      fill: true, 
      padding: 0, 
     sliceMargin: 4, 
     // Pies and donuts can start at any arbitrary angle. 
     startAngle: -90, 
     showDataLabels: false, 
     // By default, data labels show the percentage of the donut/pie. 
     // You can show the data 'value' or data 'label' instead, or 'percent' 
     dataLabels: 'value', 
      shadow: false 
     } 
    }     

    this.cfg.gridPadding = { 
     top: 0, right: 0, bottom: 0, left: 0     
    } 

    this.cfg.legend = { 
     show: false 
    } 

    this.cfg.grid = { drawBorder: false, 
     shadow: false,   
     background: "transparent" 
    }; 
} 

所以你可以在你的情況下嘗試這樣的事情? 留下您的系列的擴展配置空的,除了一個你有興趣...

function chartExtender() { 
    this.cfg.series = [ 
    { //... 
    }, 
    { // ... 
    }, 
    { 
     disableStack: true   
    } 
    ] 
} 

值得擁有的鏡頭......

+0

好的腎病的建議。 Upvoted – Kukeltje