Page 1 of 1

Custom marks arrow of piechart

Posted: Mon Mar 28, 2011 9:49 am
by 15656007
Hello,
I want to custom draw the marks arrow of piechart and I complete it in the AfterDraw event, but which the line which is not the vertical line or horizontal line , it will be more balck, is this a bug or is there any property I should to set?
The attachement is my application.
Thanks!

Re: Custom marks arrow of piechart

Posted: Tue Mar 29, 2011 10:59 am
by 10050769
Hello Candy,

I have modified your project comment the TChart.Refresh that you have in the After Draw Event and added a tChart.Draw here:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            tChart1.Draw();
        }
Could you tell us if attached project works as you expected?
Test1.zip
(23.09 KiB) Downloaded 507 times
I hope will helps.

Thanks,

Re: Custom marks arrow of piechart

Posted: Wed Mar 30, 2011 5:06 am
by 15656007
Hello,
Thanks for your reply. It works well now. But I find an other issue.When I set the 3D property of tChart to true, the coordinate of arrow's start and end is not correct.What should I do ?
Thanks!

Re: Custom marks arrow of piechart

Posted: Thu Mar 31, 2011 10:39 am
by 10050769
Hello Candy,

Sorry for the delay. If you want that arrow draw correctly when you have 3D chart you need use z value of method g.Line(Point p0,Point p1,int z). I have modified your code using (int)tChart1.Axes.Depth.Maximum to adjust the z point anyway if you prefer you can modify it as you want.
Test2.zip
(22.05 KiB) Downloaded 520 times
Could you tell us if project works as you expected?

Thanks,

Re: Custom marks arrow of piechart

Posted: Fri Apr 01, 2011 8:32 am
by 15656007
Hello,
Now I want to custom marks arrow of piechart in web using the same method as before. But it doesn't works well . There's no Draw method in webchart ,so when I load the page first ,the marks position is not changed. What should I do ?
The attachment is my web application .

Re: Custom marks arrow of piechart

Posted: Fri Apr 01, 2011 2:10 pm
by 10050769
Hello Candy,

I have modified your code, changing AfterDrawSeries to AfterDraw of Chart and adding WebChart1.Chart.Bitmap() to repaint the Chart:

Code: Select all

   protected void Page_Load(object sender, EventArgs e)
    {
        Pie pie1 = new Pie(WebChart1.Chart);
        pie1.FillSampleValues(20);
        WebChart1.Chart.Aspect.View3D = false;
        WebChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(WebChart1_AfterDraw);
        System.Drawing.Bitmap bmp = WebChart1.Chart.Bitmap((int)WebChart1.Width.Value, (int)WebChart1.Height.Value);
    }
void  WebChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
 	
 foreach (Series series in (sender as WebChart).Chart.Series)
            {
                if ((series as Steema.TeeChart.Styles.Pie) != null)
                {
                    Rectangle[] MarksOfPie = new Rectangle[series.Marks.Positions.Count];
                    int circleXCenter = (series as Steema.TeeChart.Styles.Pie).CircleXCenter;
                    int circleYCenter = (series as Steema.TeeChart.Styles.Pie).CircleYCenter;
                    int pieWidth = (series as Steema.TeeChart.Styles.Pie).CircleWidth;
                    int pieHeight = (series as Steema.TeeChart.Styles.Pie).CircleHeight;

                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        MarksOfPie[i].X = series.Marks.Positions[i].LeftTop.X;
                        MarksOfPie[i].Y = series.Marks.Positions[i].LeftTop.Y;
                        MarksOfPie[i].Width = series.Marks.Positions[i].Width;
                        MarksOfPie[i].Height = series.Marks.Positions[i].Height;
                    }

                    int NumOfLeftT = 0;
                    int NumOfRightT = 0;
                    int MaxXLeft = 0;
                    int MaxXRight = 0;
                    int NumOfLeftB = 0;
                    int NumOfRightB = 0;

                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        if (series.Marks.Positions[i].ArrowFrom.X > circleXCenter)
                        {
                            if (MaxXRight < MarksOfPie[i].X)
                            {
                                MaxXRight = MarksOfPie[i].X;

                            }
                            if (series.Marks.Positions[i].ArrowFrom.Y > circleYCenter)
                            {

                                NumOfRightB += 1;

                            }
                            else
                            {
                                NumOfRightT += 1;
                            }

                        }
                        else
                        {

                            if (MaxXLeft > MarksOfPie[i].X)
                            {
                                MaxXLeft = MarksOfPie[i].X + MarksOfPie[i].Width;
                            }

                            if (series.Marks.Positions[i].ArrowFrom.Y > circleYCenter)
                            {

                                NumOfLeftB += 1;

                            }
                            else
                            {
                                NumOfLeftT += 1;
                            }

                        }

                    }
                    int MarkMaxWidth = 0;
                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        if (series.Marks.Positions[i].ArrowFrom.X < circleXCenter)
                        {
                            if (MarksOfPie[i].Width > MarkMaxWidth)
                            {
                                MarkMaxWidth = MarksOfPie[i].Width;
                            }
                        }
                    }

                    int DistanceOfMarksLeft = 0;
                    int DistanceOfMarksRight = 0;
                    int WidthOfMarkRight = 0;
                    int WidthOfMarkLeft = 0;
                    int CountLeftT = NumOfLeftT;
                    int CountRightT = NumOfRightT;

                    int CountLeftB = NumOfLeftB;
                    int CountRightB = NumOfRightB;

                    if ((NumOfLeftT + NumOfLeftB) != 0)
                    {
                        DistanceOfMarksLeft = ((sender as WebChart).Chart.Height - 40 - MarksOfPie[0].Height * (NumOfLeftT + NumOfLeftB)) / (NumOfLeftT + NumOfLeftB);
                    }
                    if ((NumOfRightB + NumOfRightT) != 0)
                    {
                        DistanceOfMarksRight = ((sender as WebChart).Chart.Height - 40 - MarksOfPie[0].Height * (NumOfRightB + NumOfRightT)) / (NumOfRightB + NumOfRightT);

                    }
                  for (int i = series.Marks.Positions.Count - 1; i >= 0; i--)
                    {
                        series.Marks.Positions[i].Custom = true;
                        if (series.Marks.Positions[i].ArrowFrom.X < circleXCenter)
                        {
                            if (series.Marks.Positions[i].ArrowFrom.Y > circleYCenter)
                            {
                                int LeftButtonY = 20 + ((CountLeftB + NumOfLeftT) * (DistanceOfMarksLeft + MarksOfPie[0].Height));

                                series.Marks.Positions[i].ArrowTo.X = MaxXLeft;
                                series.Marks.Positions[i].ArrowTo.Y = LeftButtonY;

                                series.Marks.Positions[i].LeftTop.X = MaxXLeft;
                                series.Marks.Positions[i].LeftTop.Y = LeftButtonY;
                                //(sender as TChart).Refresh();
                                //series.RefreshSeries();
                                CountLeftB--;
                            }

                            else
                            {
                                int LeftTopY = ((CountLeftT) * (DistanceOfMarksLeft + MarksOfPie[0].Height));
                                series.Marks.Positions[i].ArrowTo.X = MaxXLeft;
                                series.Marks.Positions[i].ArrowTo.Y = LeftTopY;

                                series.Marks.Positions[i].LeftTop.X = MaxXLeft;
                                series.Marks.Positions[i].LeftTop.Y = LeftTopY;
                              //(sender as TChart).Refresh();
                               // series.RefreshSeries();
                                CountLeftT--;

                            }
                        }

                        else
                        {
                            if (series.Marks.Positions[i].ArrowFrom.Y > circleYCenter)
                            {
                                int RightButtonY = 20 + ((NumOfRightT + NumOfRightB - CountRightB) * (DistanceOfMarksRight + MarksOfPie[0].Height));
                                series.Marks.Positions[i].ArrowTo.X = MaxXRight;
                                series.Marks.Positions[i].ArrowTo.Y = RightButtonY;

                                series.Marks.Positions[i].LeftTop.X = MaxXRight;
                                series.Marks.Positions[i].LeftTop.Y = RightButtonY;
                               //(sender as TChart).Refresh();
                              //  series.RefreshSeries();
                                CountRightB--;

                            }
                            else
                            {
                                int RightTopY = 20 + ((NumOfRightT - CountRightT) * (DistanceOfMarksRight + MarksOfPie[0].Height));

                                series.Marks.Positions[i].ArrowTo.X = MaxXRight;
                                series.Marks.Positions[i].ArrowTo.Y = RightTopY;

                                series.Marks.Positions[i].LeftTop.X = MaxXRight;
                                series.Marks.Positions[i].LeftTop.Y = RightTopY;
                               //(sender as TChart).Refresh();
                             //   series.RefreshSeries();
                                CountRightT--;

                            }

                        }
                    }

                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        MarksOfPie[i].X = series.Marks.Positions[i].LeftTop.X;
                        MarksOfPie[i].Y = series.Marks.Positions[i].LeftTop.Y;
                        MarksOfPie[i].Width = series.Marks.Positions[i].Width;
                        MarksOfPie[i].Height = series.Marks.Positions[i].Height;
                    }
                    int NumLeftC = 0;
                    int NumRightC = 0;
                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        if (series.Marks.Positions[i].ArrowFrom.X < circleXCenter)
                        {
                            if (series.Marks.Positions[i].ArrowTo.Y > circleYCenter - pieHeight / 2 && series.Marks.Positions[i].ArrowTo.Y < circleYCenter + pieHeight / 2)
                            {
                                NumLeftC++;
                            }

                        }
                        else
                        {
                            if (series.Marks.Positions[i].ArrowTo.Y > circleYCenter - pieHeight / 2 && series.Marks.Positions[i].ArrowTo.Y < circleYCenter + pieHeight / 2)
                            {
                                NumRightC++;
                            }
                        }

                    }
                    int CountLeftC = NumLeftC;
                    int CountRightC = NumRightC;

                    if (NumLeftC != 0)
                    {
                        WidthOfMarkLeft = (circleXCenter - pieWidth / 2 - MaxXLeft - MarkMaxWidth) / NumLeftC;
                    }

                    if (NumOfRightT != 0)
                    {
                        WidthOfMarkRight = (MaxXRight - circleXCenter - pieWidth / 2) / NumRightC;
                    }

                    CountRightT = NumOfRightT;
                    CountLeftT = NumOfLeftT;
                    for (int i = 0; i < series.Marks.Positions.Count; i++)
                    {
                        int arrowstartX = series.Marks.Positions[i].ArrowFrom.X;
                        int arrowstartY = series.Marks.Positions[i].ArrowFrom.Y;
                        int MarksX = series.Marks.Positions[i].ArrowTo.X;
                        int MarksY = series.Marks.Positions[i].ArrowTo.Y;


                        if (MarksX > circleXCenter)
                        {
                            if (MarksY < circleYCenter - pieHeight / 2)
                            {

                                g.Line(new Point(arrowstartX, arrowstartY), new Point(arrowstartX, series.Marks.Positions[i].LeftTop.Y), (int)WebChart1.Chart.Axes.Depth.Maximum);
                                g.Line(new Point(arrowstartX, series.Marks.Positions[i].LeftTop.Y), new Point(MarksX, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);
                               

                            }
                            else if (MarksY > circleYCenter - pieHeight / 2 && MarksY < circleYCenter + pieHeight / 2)
                            {

                                g.Line(new Point(arrowstartX, arrowstartY), new Point(MarksX, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);

                               
                            }
                            else
                            {
                                g.Line(new Point(arrowstartX, arrowstartY), new Point(arrowstartX, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);
                                g.Line(new Point(arrowstartX, MarksY), new Point(MarksX, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);

                            }
                        }
                        else
                        {
                            if (MarksY < circleYCenter - pieHeight / 2)
                            {

                                g.Line(new Point(arrowstartX, arrowstartY), new Point(arrowstartX, series.Marks.Positions[i].LeftTop.Y), (int)WebChart1.Chart.Axes.Depth.Maximum);
                                g.Line(new Point(arrowstartX, series.Marks.Positions[i].LeftTop.Y), new Point(MarksX + MarksOfPie[i].Width, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);

                            }

                            else if (MarksY > circleYCenter - pieHeight / 2 && MarksY < circleYCenter + pieHeight / 2)
                            {
                                g.Line(new Point(arrowstartX, arrowstartY), new Point(MarksX + MarksOfPie[i].Width, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);
                             }
                            else
                            {

                                g.Line(new Point(arrowstartX, arrowstartY), new Point(arrowstartX, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);
                                g.Line(new Point(arrowstartX, MarksY), new Point(MarksX + MarksOfPie[i].Width, MarksY), (int)WebChart1.Chart.Axes.Depth.Maximum);
                            }

                        }

                    }
                }
            }
        }
Could you please, check if previous code works as you want?

I hope will helps.

Thanks,