原創|其它|編輯:郝浩|2010-05-11 11:09:19.000|閱讀 3975 次
概述:DevExpress的PivotGrid控件,無論是WinForm的XtraPivotGrid,還是WebForm的AspxPivotGrid,都能夠實現強大的多維分析功能,完全可以當成一個決策分析工具來使用,然而,美中不足的就是沒有關聯到圖形圖表Chart。雖然有了分析的結果,但是沒有圖形圖表更加直觀地表達效果。因此,在DevExpress 控件包使用方面有多年研究的慧都控件網愿把PivotGrid控件的使用心得分享給大家。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DevExpress的PivotGrid控件,無論是WinForm的XtraPivotGrid,還是WebForm的AspxPivotGrid,都能夠實現強大的多維分析功能,完全可以當成一個決策分析工具來使用,然而,美中不足的就是沒有關聯到圖形圖表Chart。雖然有了分析的結果,但是沒有圖形圖表更加直觀地表達效果。因此,在DevExpress 控件包使用方面有多年研究的慧都控件網愿把PivotGrid控件的使用心得分享給大家。
為了把PivotGrid連接到Chart,首先利用PivotGrid自帶的編程接口獲取篩選屬性,形成交差表,再使用Office Web Control(OWC)來展示圖形。
OWC顯示圖形的例子
引用DLL
using OWC11;
//創建X坐標的值,表示月份
int[] Month ={ 1, 2, 3 };
//創建Y坐標的值,表示銷售額
double[] Count ={ 120, 240, 220 };
string strDataName = "";
string strData = "";
//創建圖表空間
ChartSpace mychartSpace = new ChartSpace();
//mychartSpace.DataSource = oleReader;
//mychartSpace.Border.DashStyle = ChartLineDashStyleEnum.chLineRoundDot;
//在圖表空間內添加一個圖表對象
ChChart mychart = mychartSpace.Charts.Add(0);
mychart.Border.DashStyle = ChartLineDashStyleEnum.chLineSolid;
//設置每塊餅的數據
for (int i = 0; i < Count.Length; i++)
{
if (i != Count.Length - 1)
{
strDataName += Month[i] + "\t";
strData += Count[i].ToString() + "\t";
}
else
{
strDataName += Month[i];
strData += Count[i].ToString();
}
}
//設置圖表類型,本例使用柱形
mychart.Type = ChartChartTypeEnum.chChartTypePie;
//設置圖表的一些屬性
//是否需要圖例
mychart.HasLegend = true;
//是否需要主題
mychart.HasTitle = true;
//主題內容
mychart.Title.Caption = "一季度總結";
//添加圖表塊
mychart.SeriesCollection.Add(0);
//設置圖表塊的屬性
//分類屬性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
//值屬性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);
//mychart.Axes[1].Font.Bold = true;
mychart.Legend.Border.DashStyle = ChartLineDashStyleEnum.chLineDash;
//顯示百分比
ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
//mytb.HasPercentage = true;
//生成圖片
mychartSpace.ExportPicture(Server.MapPath(".") + @"\test.gif", "gif", 500, 450);
//加載圖片
顯示的效果圖
獲取Pivot各個區域Area的值
#region 獲取相應Area內容
protected System.Collections.Generic.ICollection<PivotGridField> GetFilterFields(ASPxPivotGrid _grid)
{
return GetFieldsByArea(_grid, DevExpress.XtraPivotGrid.PivotArea.FilterArea);
}
protected System.Collections.Generic.ICollection<PivotGridField> GetColumnFields(ASPxPivotGrid _grid)
{
return GetFieldsByArea(_grid, DevExpress.XtraPivotGrid.PivotArea.ColumnArea);
}
protected System.Collections.Generic.ICollection<PivotGridField> GetRowFields(ASPxPivotGrid _grid)
{
return GetFieldsByArea(_grid, DevExpress.XtraPivotGrid.PivotArea.RowArea);
}
protected System.Collections.Generic.ICollection<PivotGridField> GetDataFields(ASPxPivotGrid _grid)
{
return GetFieldsByArea(_grid, DevExpress.XtraPivotGrid.PivotArea.DataArea);
}
protected System.Collections.Generic.ICollection<PivotGridField> GetFieldsByArea(ASPxPivotGrid _grid, DevExpress.XtraPivotGrid.PivotArea _area)
{
System.Collections.Generic.List<PivotGridField> _list = new List<PivotGridField>();
foreach (DevExpress.Web.ASPxPivotGrid.PivotGridField _field in _grid.Fields)
{
if (_field.Area == _area)
{
_list.Add(_field);
}
}
return _list;
}
#endregion
是Windows和ASP.NET控件套包、IDE報表生成工具和企業應用程序框架。長期占據著慧都科技控件銷量榜的第一位置。在慧都控件網的推動下,DXperience幫助中國軟件企業開發出很多優秀的軟件產品 DXperience其產品的品牌、質量,是全球公認的。慧都控件網為 DXperience提供了全面的技術支持服務,同時提供。
同時,慧都為DevExpress for .NET用戶量身打造了一款中文資源包,DevExpress 官方漢化資源 , 您只需極少花費便可獲得這套完整、專業的漢化資源,從而使您的產品實現全面漢化。
(慧都控件網版權所有,轉載請注明出處,否則追究法律責任)
標簽:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網