예제 #1
0
 void lbPosition_SelectedIndexChanged(object sender, RoutedEventArgs e)
 {
     if (chart != null)
     {
         PieSeries.SetLabelPosition(Series.Label, (PieLabelPosition)lbPosition.SelectedItem);
     }
 }
예제 #2
0
        public static ChartControl CreatPieChart(SolidColorBrush forecolor, string ChartTitle, List <ChartDataChartCommonData> dtchart)
        {
            mausac = 0;
            ChartControl    abc = new ChartControl();
            SimpleDiagram2D dg1 = new SimpleDiagram2D();
            //liabc.Titles.Clear();
            //Tao Tile cho Chart
            Title nt = new Title();

            nt.Content    = ChartTitle;
            nt.Foreground = forecolor;
            abc.Titles.Add(nt);
            //Tinh so Series
            List <string> countsr = (from p in dtchart group p by p.Series into g select g.Key).ToList();

            //Creat Diagram
            abc.Diagram = dg1;
            GridControl dtl = new GridControl();

            for (int i = 0; i < countsr.Count; i++)
            {
                PieSeries2D dgs1 = new PieSeries2D();
                dgs1.HoleRadiusPercent = 0;                      //Thiet lap khoang trong tu tam hinh tron den duong tron
                dgs1.ArgumentScaleType = ScaleType.Auto;
                foreach (ChartDataChartCommonData dr in dtchart) //Tao cac point
                {
                    if (dr.Series == countsr.ElementAt(i))
                    {
                        //Tao Series
                        SeriesPoint sr1 = new SeriesPoint();
                        sr1.Argument = dr.Agrument + ":" + dr.Value.ToString();
                        sr1.Value    = dr.Value;
                        sr1.Tag      = mausac.ToString();
                        dgs1.Points.Add(sr1);
                        mausac++;
                    }
                }
                dgs1.Label = new SeriesLabel();//Tao Label cho Diagram
                PieSeries.SetLabelPosition(dgs1.Label, PieLabelPosition.TwoColumns);
                dgs1.Label.RenderMode = LabelRenderMode.RectangleConnectedToCenter;
                dgs1.LabelsVisibility = true;//Hien thi Lablel cho tung vung
                PointOptions pn1 = new PointOptions();
                pn1.PointView = PointView.ArgumentAndValues;
                pn1.Pattern   = "{A} ({V})";                //Tao mau chu thich
                NumericOptions nbm1 = new NumericOptions(); //Tao Kieu hien thi
                nbm1.Format             = NumericFormat.Percent;
                pn1.ValueNumericOptions = nbm1;
                PieSeries2D.SetPercentOptions(pn1, new PercentOptions()
                {
                    ValueAsPercent = true, PercentageAccuracy = 5
                });                                                                                                        //Quy dinh ty le phan tram chinh xac
                dgs1.PointOptions = pn1;
                dg1.Series.Add(dgs1);
                //Tao chu thich
                dgs1.LegendPointOptions = pn1;
            }
            abc.Legend = new Legend();
            //End tao chu thich
            //Set mau sac cho seriespont
            abc.CustomDrawSeriesPoint += abc_CustomDrawSeriesPoint;
            return(abc);
        }