Ejemplo n.º 1
0
        /// <summary>
        /// 根据数据创建一个图形展现
        /// </summary>
        /// <param name="caption">图形标题</param>
        /// <param name="viewType">图形类型</param>
        /// <param name="dt">数据DataTable</param>
        /// <param name="rowIndex">图形数据的行序号</param>
        /// <returns></returns>
        private Series CreateOldSeries(string caption, ViewType viewType, DataTable dt, int rowIndex)
        {
            seriesCommon.Points.Clear();
            Series series = seriesCommon;

            int curMonth = System.DateTime.Now.Month;
            int curYear  = System.DateTime.Now.Year;

            //  int dataYear = int.Parse(caption);
            if (dt == null)
            {
                return(null);
            }
            DevExpress.XtraCharts.PieSeriesView pieSeriesView1 = new DevExpress.XtraCharts.PieSeriesView();
            DevExpress.XtraCharts.SeriesTitle   seriesTitle1   = new DevExpress.XtraCharts.SeriesTitle();
            seriesTitle1.Text = caption;
            pieSeriesView1.Titles.AddRange(new DevExpress.XtraCharts.SeriesTitle[] {
                seriesTitle1
            });

            series.View = pieSeriesView1;

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                string  argument = dt.Columns[i].ColumnName;      //参数名称
                decimal value    = (decimal)dt.Rows[rowIndex][i]; //参数值
                series.Points.Add(new SeriesPoint(argument, value));
            }

            //必须设置ArgumentScaleType的类型,否则显示会转换为日期格式,导致不是希望的格式显示
            //也就是说,显示字符串的参数,必须设置类型为ScaleType.Qualitative
            series.ArgumentScaleType = ScaleType.Qualitative;
            series.LabelsVisibility  = DevExpress.Utils.DefaultBoolean.True;//显示标注标签

            //     DevExpress.XtraCharts.PiePointOptions piePointOptionsValue = new PiePointOptions();
            //   piePointOptionsValue.PointView = DevExpress.XtraCharts.PointView.ArgumentAndValues;
            /// series.LegendPointOptions = piePointOptionsValue;

            return(series);
        }
        private void IniPie(ChartControl chartControl, DataTable table, MouseEventHandler mouseEventHandler, string PaletteColorName)
        {
            try
            {
                int      iCount      = table.Rows.Count;
                int      i           = 0;
                Series[] ArraySeries = new Series[iCount];
                foreach (DataRow dr in table.Rows)
                {
                    DevExpress.XtraCharts.Series            series             = new DevExpress.XtraCharts.Series();
                    DevExpress.XtraCharts.PieSeriesView     pieSeriesView      = new DevExpress.XtraCharts.PieSeriesView();
                    DevExpress.XtraCharts.PieSeriesLabel    pieSeriesLabel1    = new DevExpress.XtraCharts.PieSeriesLabel();
                    DevExpress.XtraCharts.SeriesTitle       seriesTitle1       = new DevExpress.XtraCharts.SeriesTitle();
                    DevExpress.XtraCharts.PieWidenAnimation pieWidenAnimation1 = new DevExpress.XtraCharts.PieWidenAnimation();
                    //
                    ((System.ComponentModel.ISupportInitialize)(chartControl)).BeginInit();
                    ((System.ComponentModel.ISupportInitialize)(pieSeriesLabel1)).BeginInit();
                    ((System.ComponentModel.ISupportInitialize)(series)).BeginInit();
                    ((System.ComponentModel.ISupportInitialize)(pieSeriesView)).BeginInit();
                    //
                    chartControl.Legend.Visibility    = DevExpress.Utils.DefaultBoolean.False;
                    pieSeriesLabel1.BackColor         = System.Drawing.Color.Transparent;
                    pieSeriesLabel1.Border.Visibility = DevExpress.Utils.DefaultBoolean.False;
                    pieSeriesLabel1.ColumnIndent      = 20;
                    pieSeriesLabel1.Font        = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
                    pieSeriesLabel1.LineLength  = 30;
                    pieSeriesLabel1.Position    = DevExpress.XtraCharts.PieSeriesLabelPosition.Inside;
                    pieSeriesLabel1.TextPattern = "{A}\n{V}";
                    pieSeriesLabel1.Font        = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    //
                    seriesTitle1.Dock = DevExpress.XtraCharts.ChartTitleDockStyle.Bottom;
                    pieSeriesView.Titles.AddRange(new DevExpress.XtraCharts.SeriesTitle[] {
                        seriesTitle1
                    });
                    pieSeriesView.Animation = pieWidenAnimation1;
                    //
                    series.Label = pieSeriesLabel1;
                    series.View  = pieSeriesView;
                    series.Name  = dr["Name"].ToString();
                    series.Tag   = dr["DSA"];

                    DevExpress.XtraCharts.SeriesPoint seriesPoint = new DevExpress.XtraCharts.SeriesPoint(dr["Value"], dr["Count"], 0);
                    seriesPoint.Tag = dr["Name"].ToString();
                    if (PaletteColorName.Length > 0)
                    {
                        seriesPoint.ColorSerializable = ToHexColor(this.chartControl1.PaletteRepository["Chameleon"][i].Color);
                    }
                    else
                    {
                        seriesPoint.ColorSerializable = ToHexColor(Color.Wheat);
                    }
                    series.Points.Add(seriesPoint);
                    ArraySeries[i++] = series;

                    //
                    ((System.ComponentModel.ISupportInitialize)(pieSeriesLabel1)).EndInit();
                    ((System.ComponentModel.ISupportInitialize)(series)).EndInit();
                    ((System.ComponentModel.ISupportInitialize)(pieSeriesView)).EndInit();
                    ((System.ComponentModel.ISupportInitialize)(chartControl)).EndInit();
                    //
                }
                chartControl.AnimationStartMode = DevExpress.XtraCharts.ChartAnimationMode.OnDataChanged;
                chartControl.SelectionMode      = ElementSelectionMode.Single;
                chartControl.SeriesSerializable = ArraySeries;
                chartControl.Dock        = DockStyle.Fill;
                chartControl.MouseClick += mouseEventHandler;
                chartControl.BorderOptions.Visibility = DevExpress.Utils.DefaultBoolean.False;
            }
            catch { }
        }