有兄弟知道xtraPivotGrid 里面占比怎么弄吗
在透视的过程中,可以选择要横占比还是列占比。
一直困挠着,望兄弟们一定要帮忙啊。 --------------------编程问答-------------------- 那个应该是汇总的意思吧。最好给出具体公式,如果说自带的count、sum、avg等汇总公示不能满足需求的话(就没占比的汇总公式嘛),需要自定义汇总公式实现。 --------------------编程问答-------------------- 这里有个例子,自己参考下:
--------------------编程问答-------------------- 比如
using DevExpress.XtraPivotGrid;
fieldExtendedPrice.Caption = "Percentage of Orders over $500";
// Enable a custom summary calculation for the Extended Price field.
fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom;
// Specify the settings used to format values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
fieldExtendedPrice.CellFormat.FormatString = "p";
int minSum = 500;
private void pivotGridControl1_CustomSummary(object sender,
PivotGridCustomSummaryEventArgs e) {
if(e.DataField != fieldExtendedPrice) return;
// A variable which counts the number of orders whose sum exceeds $500.
int order500Count = 0;
// Get the record set corresponding to the current cell.
PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
// Iterate through the records and count the orders.
for(int i = 0; i < ds.RowCount; i++) {
PivotDrillDownDataRow row = ds[i];
// Get the order's total sum.
decimal orderSum = (decimal)row[fieldExtendedPrice];
if(orderSum >= minSum) order500Count ++;
}
// Calculate the percentage.
if(ds.RowCount > 0) {
e.CustomValue = (decimal)order500Count/ds.RowCount;
}
}
数量1 ,区域1,占比1,数量2,区域2 ,占比2
4 河南 40% 6 大连 60%
这个是横占比
列占比也希望能实现这样的效果。 --------------------编程问答-------------------- 那个例子看来吗?通过自定义CustomSummary事件就可以实现你那个效果,顺便给你看下效果图:
--------------------编程问答-------------------- 谢谢 qldsrx 我试试。
补充:.NET技术 , C#