private void chartControl1_ObjectHotTracked(object sender, DevExpress.XtraCharts.HotTrackEventArgs e) { SeriesPoint point = e.AdditionalObject as SeriesPoint; if (point != null) { PivotChartDataSourceRowItem coord = point.Tag as PivotChartDataSourceRowItem; ChartControl chart = (ChartControl)sender; PivotGridControl pivot = (PivotGridControl)chart.DataSource; PivotCellEventArgs info = pivot.Cells.GetCellInfo(coord.CellX, coord.CellY); PivotSummaryDataSource source = info.CreateSummaryDataSource(); string s = string.Empty; for (int i = 0; i < source.RowCount; i++) { s += "Country = " + source.GetValue(i, 0).ToString() + "\r\tYear = " + source.GetValue(i, 1).ToString() + "\r\tExtended Price = " + source.GetValue(i, 2).ToString() + "\r\n"; } toolTipController1.ShowHint(s); } else { toolTipController1.HideHint(); } }
void CalculateSalesPerProduct() { Dictionary <string, decimal> sales = new Dictionary <string, decimal>(); PivotSummaryDataSource ds = pivotGridControl1.CreateSummaryDataSource(); for (int i = 0; i < ds.RowCount; i++) { string product = (string)ds.GetValue(i, fieldProduct); decimal sale = (decimal)ds.GetValue(i, fieldRank); if (sales.ContainsKey(product)) { sales[product] += sale; } else { sales.Add(product, sale); } } totalSales = new List <decimal>(sales.Count); foreach (decimal value in sales.Values) { totalSales.Add(value); } totalSales.Sort(ReverseDecimalSort); }
// Returns a list of summary values against which // a Custom Total will be calculated. private ArrayList GetSummaryValues(PivotCellValueEventArgs e) { ArrayList values = new ArrayList(); // Creates a summary data source. PivotSummaryDataSource sds = e.CreateSummaryDataSource(); // Iterates through summary data source records // and copies summary values to an array. for (int i = 0; i < sds.RowCount; i++) { object value = sds.GetValue(i, e.DataField); if (value == null) { continue; } values.Add(value); } // Sorts summary values. values.Sort(); // Returns the summary values array. return(values); }
protected void ASPxPivotGrid1_CustomCellValue(object sender, DevExpress.Web.ASPxPivotGrid.PivotCellValueEventArgs e) { if (ReferenceEquals(e.RowCustomTotal, null)) { return; } if (e.RowCustomTotal.SummaryType == DevExpress.Data.PivotGrid.PivotSummaryType.Sum) { PivotSummaryDataSource ds = e.CreateSummaryDataSource(); decimal customSum = 0; for (int i = 0; i < ds.RowCount; i++) { customSum += Convert.ToDecimal(ds.GetValue(i, e.DataField)); } e.Value = customSum; } else if (e.RowCustomTotal.SummaryType == DevExpress.Data.PivotGrid.PivotSummaryType.Average) { PivotSummaryDataSource ds = e.CreateSummaryDataSource(); if (ds.RowCount == 0) { return; } decimal customAverage = 0; for (int i = 0; i < ds.RowCount; i++) { customAverage += Convert.ToDecimal(ds.GetValue(i, e.DataField)); } e.Value = customAverage / ds.RowCount; } }
private DataTable CreateSummaryTable(ASPxPivotGrid pivotGrid, PivotGridField sourceField, PivotGridField targetField, PivotGridField valueField, object sourceFieldValue) { PivotSummaryDataSource ds = ASPxPivotGrid1.CreateSummaryDataSource(); DataTable dt = new DataTable(); dt.Columns.Add("SourceField", typeof(string)); dt.Columns.Add("TargetField", typeof(string)); dt.Columns.Add("Value", typeof(decimal)); for (int i = 0; i < ds.RowCount; i++) { if (ds.GetValue(i, sourceField) == sourceFieldValue) { dt.Rows.Add(new object[] { ds.GetValue(i, sourceField), ds.GetValue(i, targetField), ds.GetValue(i, valueField) }); } } return(dt); }
void CalculateSalesPerYear() { salesPerYear = new Dictionary <int, List <decimal> >(); PivotSummaryDataSource ds = pivotGridControl1.CreateSummaryDataSource(); for (int i = 0; i < ds.RowCount; i++) { int year = (int)ds.GetValue(i, fieldYear); List <decimal> list; if (!salesPerYear.TryGetValue(year, out list)) { list = new List <decimal>(); salesPerYear.Add(year, list); } list.Add((decimal)ds.GetValue(i, fieldRank)); } foreach (List <decimal> list in salesPerYear.Values) { list.Sort(ReverseDecimalSort); } }
/// <summary> /// 포커스가 가 있는 그리드의 정보를 데이터 테이블로 변환한다. /// </summary> /// <param name="pGrid">그리드.</param> /// <returns>리턴값</returns> public static DataTable GetPivotFocusedCellInfo(PivotGridControl pGrid, DataReturnType type) { try { DataTable table = new DataTable(); if (type == DataReturnType.FocusedCell) { PivotSummaryDataSource dataSource = pGrid.Cells.GetFocusedCellInfo().CreateSummaryDataSource() as PivotSummaryDataSource; ITypedList list = dataSource as ITypedList; foreach (PropertyDescriptor property in list.GetItemProperties(null)) { table.Columns.Add(property.Name, property.PropertyType); } for (int rowIndex = 0; rowIndex < dataSource.RowCount; rowIndex++) { object[] values = new object[table.Columns.Count]; for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++) { values[columnIndex] = dataSource.GetValue(rowIndex, /*rowIndex*/ columnIndex); } table.Rows.Add(values); } } else if (type == DataReturnType.All) { PivotSummaryDataSource dataSourceAll = pGrid.CreateSummaryDataSource() as PivotSummaryDataSource; ITypedList listAll = dataSourceAll as ITypedList; foreach (PropertyDescriptor property in listAll.GetItemProperties(null)) { table.Columns.Add(property.Name, property.PropertyType); } for (int rowIndex = 0; rowIndex < dataSourceAll.RowCount; rowIndex++) { object[] values = new object[table.Columns.Count]; for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++) { values[columnIndex] = dataSourceAll.GetValue(rowIndex, /*rowIndex*/ columnIndex); } table.Rows.Add(values); } } return(table); } catch (Exception ex) { throw ex; } }
private DataTable ConvertPivotSummaryDataSourceToDataTable(PivotSummaryDataSource source) { DataTable dt = new DataTable(); foreach (PropertyDescriptor _propertyDescriptor in source.GetItemProperties(null)) { dt.Columns.Add(_propertyDescriptor.Name, _propertyDescriptor.PropertyType); } for (int r = 0; r < source.RowCount; r++) { object[] rowValues = new object[dt.Columns.Count]; for (int c = 0; c < dt.Columns.Count; c++) { rowValues[c] = source.GetValue(r, dt.Columns[c].ColumnName); } dt.Rows.Add(rowValues); } return(dt); }
public static DataTable ConvertSummaryDataSourceToDataTable(PivotSummaryDataSource source) { DataTable result = new DataTable(); ITypedList dataProperties = source as ITypedList; if (dataProperties == null) { return(result); } foreach (PropertyDescriptor prop in dataProperties.GetItemProperties(null)) { result.Columns.Add(prop.Name, prop.PropertyType); } for (int row = 0; row < source.RowCount; row++) { List <object> values = new List <object>(); foreach (DataColumn col in result.Columns) { values.Add(source.GetValue(row, col.ColumnName)); } result.Rows.Add(values.ToArray()); } return(result); }