商务合作:179001057@qq.com

ComponentOne之WebChart概述

技术2022-05-11  0


某平台价值19860元的编程课程资料免费领取【点我领取】


(一). 写本文章目的:    

         学了一段时间ComponentOne的图表,感觉ComponenOne图表控件还可以,图表样式也较丰富

  不过它的帮助全是英文的,而且有些地方写的比较粗糙,示例程序也不够详细. 我把它总结了一下.

(二).使用方法        

        1.安装好ComponentOne软件.

         2.建立一个WEB应用程序项目,名称为: TextChart

         3.将ComponentOne软件自带的控件集DLL文件(不一定全部,只把需要的一部分)拷贝到自己刚建的

            项目TextChart的Bin目录下面 (这里要手动放的原因是ComponentOne有时会找不到Dll)  

         4.双击项目里任何一个*.aspx文件,打开设计界面。 打开工具栏,在工具栏空白处右击,选“添加/删除”

             项,打开自定义控件窗口,在.net frame 组件选项卡下选择ComponentOne相应的组件,如果有清楚,

             就将所有的C1开头的全部勾选,点“确定按钮".  则ComponentOne的控件就显示在工具箱里面了  :)

         5. 到了这一步,就可以将ComponentOne控件像一般控件一样直接拖动使用了. 拖C1WebChart控件到

            窗体页面上.  然后右击控件,选 "Chart wizard..."就可以为其设置显示的样式(饼图/柱状图/折线图等)和

            属性了,用法跟一般控件差不多。(如果感觉还是陌生的话,请看下面(三),除了用设计器设置外,

           还可以代码用代码设置)

(三) . 代码设置

         1. 限于篇幅,只讲解主要的属性

         2.所有的图表样式原理差不多都一样的,这里只讲一下饼图的实现方法

       

          using C1.Web.C1WebChart;            //命名空间,必需加入,否则找不到里面的类和方法等          using C1.Web.C1WebChartBase;          using C1.Win.C1Chart;

           protected C1.Web.C1WebChart.C1WebChart C1WebChart1;   // 控件声明

 

 

         1) 

主要属性

          C1WebChart1.Header.Text="Chart 头";               //图表头标题          C1WebChart1.Footer.Text="Chart 尾";                 //图表尾文本          C1WebChart1.BackColor = Color.LightSteelBlue;   //背景色          C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;  //图像存储格式         

           C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Bar;   //图表

                                                       // 类型,Chart2DTypeEnum枚举下有所有的图表样式,如饼图/柱状图等

                                                                                                                                 C1WebChart1.Width=800;     //图表宽度

         

          2)

主要方法

            a .X轴标签(坐标)的方法,直接调用即可

               public void AddAxisX()               {                          // label x axis with product names                      Axis ax = C1WebChart1.ChartArea.AxisX;                      ax.ValueLabels.Clear();                        ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;                     for(int i = 0; i < 100; i++)                     {                              //DataRowView drv = dv[i];                             ax.ValueLabels.Add(i, (i+1).ToString());                     }                     try                     {                             ax.Max = 10 - .5;                     }                    catch {}                   }            a .Y轴标签(坐标)的方法,直接调用即可

                public void AddAxisY()                {                        // label y axis with product names                     Axis ay = C1WebChart1.ChartArea.AxisY;                    ay.ValueLabels.Clear();                      ay.AnnoMethod = AnnotationMethodEnum.ValueLabels;                    for(int i = 0; i < 10; i++)                    {                          //DataRowView drv = dv[i];                         ay.ValueLabels.Add(i, (50*i).ToString());                   }                   try                    {                            ay.Max = 20 - .5;                    }                   catch {}                   }

              c.画图表的方法                public void GetPieData()                {                         C1WebChart1.Legend.Visible = true;  //图表区块注释.                       this.AddAxisX();   //上面方法a                       this.AddAxisY();   //上面方法b                          //生成数据                        PointF[] data = new PointF[10];                        for (int i = 0; i < data.Length; i++)                        {                                float y = float.Parse((3*i+5).ToString());                                data[i] = new PointF(i, y);                        }                               //清除现有的饼图                       ChartDataSeriesCollection dscoll = C1WebChart2.ChartGroups[0].ChartData.SeriesList;                          dscoll.Clear();

                       //汇图,即将点数组交给控件,它会自己分配,并画出图形                        ChartDataSeries series = C1WebChart1.ChartGroups[0].ChartData.SeriesList[0];                       series.PointData.CopyDataIn(data);// 这里的data是PointF类型                                      //给区块加标签                        for(int i=0; i < data.Length; i++)                       {                               ChartDataSeries series = dscoll.AddNewSeries();                               series.PointData.Length = 1;                               series.Y[0] = data[i].Y;                              series.Label="我是:"+(i+1).ToString();

                               //加标签                               C1.Win.C1Chart.Label lbl = C1WebChart1.ChartLabels.LabelsCollection.AddNewLabel();                               lbl.Text = string.Format("{0} ({1:c})","第:"+i.ToString()+"扇区", data[i].Y);                               lbl.Compass = LabelCompassEnum.Radial;                               lbl.Offset = 20;                               lbl.Connected = true;                               lbl.Visible = true;                               lbl.AttachMethod = AttachMethodEnum.DataIndex;                               AttachMethodData am = lbl.AttachMethodData;                              am.GroupIndex  = 0;                             am.SeriesIndex = i;                             am.PointIndex  = 0;                         }                  } 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=480916


最新回复(0)