DevExpress之ChartControl实现柱状图演示实例
本文实例讲述了DevExpress中ChartControl实现柱状图演示的方法。分享给大家供大家参考。具体实现方法如下:
关键代码如下:
usingSystem; usingSystem.Data; usingSystem.Windows.Forms; usingCSharpUtilHelpV2; usingDevExpress.XtraCharts;
namespaceDevExpressChart { publicpartialclasswinProduct:Form { publicwinProduct() { InitializeComponent(); } staticreadonlystringAccessFullPath=string.Format(@"{0}\Northwind.MDB",AppDomain.CurrentDomain.BaseDirectory); staticDataTableProductList=null; AccessUtilsV2AccessHelper=null; privatevoidwinChat_Load(objectsender,EventArgse) { AccessHelper=newAccessUtilsV2(AccessFullPath); ProductList=AccessHelper.ExecuteDataTable("select*fromProducts",null); BuilderDevChart(); } privatevoidBuilderDevChart() { if(ProductList!=null) { Series_barSeries=newSeries("测试",ViewType.Bar); _barSeries.ArgumentDataMember="ProductName";//x轴 _barSeries.ValueDataMembers[0]="UnitPrice";//Y轴 _barSeries.DataSource=ProductList; _barSeries.AddDataFilter("CategoryID",4,DataFilterCondition.Equal); _barSeries.SetColorEach(true); chartControl1.Series.Add(_barSeries); _barSeries.LegendPointOptions.PointView=PointView.ArgumentAndValues;
//chartControl1.SeriesDataMember="UnitPrice"; //chartControl1.SeriesTemplate.ValueDataMembers[0]="UnitPrice"; //chartControl1.SeriesTemplate.ArgumentDataMember="ProductName"; //chartControl1.SeriesTemplate.ArgumentScaleType=ScaleType.Qualitative; //chartControl1.SeriesTemplate.AddDataFilter("CategoryID",4,DataFilterCondition.Equal); //chartControl1.SeriesTemplate.LegendPointOptions.PointView=PointView.ArgumentAndValues; chartControl1.SetXLableAngle(-35); chartControl1.SetCrosshair(true);
chartControl1.Legend.Direction=LegendDirection.LeftToRight; chartControl1.Legend.AlignmentHorizontal=LegendAlignmentHorizontal.Center; chartControl1.Legend.AlignmentVertical=LegendAlignmentVertical.BottomOutside; chartControl1.DataSource=ProductList;
chartControl1.AddTitle("ProductList"); //-------------------------- } } } }