使用Devexpress ChartControl中的Pie图

       ChartControl 图标控件有很多种类,以前使用过SwiftPlotDiagram类型 做过实时数据显示,感觉非常好用。

一般的图表显示,要么是那种折线,柱状图,饼图等。来看看饼图是怎么使用的。 上图先:
使用Devexpress ChartControl中的Pie图_第1张图片

它也可以显示成3D形式的,具体就不再说了。绑定到它的数据源的方式有很多种 List,Array,DataTable,Xml格式等。例子中使用的List
   /// 
    /// 集合类
    /// 
    public class RecordList : System.Collections.CollectionBase
    {
        public RecordData this[int index]
        {
            get { return (RecordData)(List[index]); }
            set { List[index] = value; }
        }
        public int Add(RecordData contact)
        {
            return this.List.Add(contact);
        }
    }
    /// 
    /// 数据类
    /// 
    public class RecordData
    {
        public RecordData(string name, int id)
        {
            this._name = name;
            this._id = id;
        }
        public RecordData(string name)
        {
            this._name = name;
            Id++;
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private int _id = 0;
        public int Id
        {
            get { return _id; }
            set
            {
                _id = value;
            }
        }

    }

绑定代码:
  RecordList list = new RecordList();
            list.Add(new RecordData("第一季度", 10));
            list.Add(new RecordData("第二季度", 20));
            list.Add(new RecordData("第三季度", 30));
            list.Add(new RecordData("第四季度", 40));
            
            ChartControl myChart = this.chartControl1;
            myChart.DataSource = list;

            Series mySeries = new Series("Series1", ViewType.Pie);  // 这是图形类型
            myChart.Series.Add(mySeries);
            mySeries.ArgumentDataMember = "Name";   // 绑定参数
            mySeries.ValueDataMembers.AddRange(new string[] { "Count" });   // 绑定值
            mySeries.Label.PointOptions.PointView = PointView.ArgumentAndValues;   // 设置Label显示方式
            //mySeries.ToolTipPointPattern = "hello world";   // 自定义ToolTip显示
            mySeries.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;  // 设置鼠标悬浮显示toolTip
            //mySeries.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.FixedPoint;
            //mySeries.ValueScaleType = ScaleType.Numerical;
            //mySeries.Label.PointOptions.ValueNumericOptions.Precision = 2;

当然显示数据的格式可以是数值,百分比等。

你可能感兴趣的:(使用Devexpress ChartControl中的Pie图)