Page 1 of 1

How to redraw circles drawn using custom drawing?

Posted: Fri Sep 04, 2009 7:58 am
by 9346725
Hi,
I have 10 fast line series. In each of the series, if there is a null value then i am drawing one custom circle to show the start and end of the null values.
Now, from legend control, when i am unchecking the series - means making the series as invisible, the series goes off but the circles remains there.
How to solve this problem?
I am drawing those circles on beforedrawSeries event using the Graphics3D object.

Please help.
See the image below -
[img]
UndrawProblem.PNG
UndrawProblem.PNG (33.4 KiB) Viewed 9910 times
[/img]

Re: How to redraw circles drawn using custom drawing?

Posted: Fri Sep 04, 2009 8:16 am
by narcis
Hi Nitin,

Before doing the drawing in the BeforeDrawSeries event I'd check if that specific series is visible (FastLine.Visible or FastLine.Active) and only do the drawing if series is visible otherwise don't do that.

Re: How to redraw circles drawn using custom drawing?

Posted: Fri Sep 04, 2009 10:45 am
by 9346725
Sorry, i could not understand.
I am drawing all the series by default. Then from legend control (not teechart legend) it raise an event when the check box is changed. Based on that i am making the series visible or invisible. But the circles are custom drawn. With the series goes invisble, the circles are not going off.
Please have a look into the code below -

Code: Select all

        //Event to make the series visible or invisible
        void _TagInfo_OnVisibleStateChanged(object sender, bool visible)
        {
            TagInfo _TagInfo = sender as TagInfo;
            TeeChart.Series.WithTitle(_TagInfo.TagName).Visible = visible;
            TeeChart.Refresh(); //this call is also very costly. But to call the 
                                           //BeforeDrawSeries event i need to call this function. Is it right?
        }

        private void TeeChart_BeforeDrawSeries(object sender, Graphics3D g)
        {
            //Draw circles between the Null Value ranges in each of the series
            if (this.TeeChart.Series.Count > 0)
            {
                foreach (Series _Series in TeeChart.Series)
                {
                    if (_Series.Visible)
                        DrawCircle(g);
                }
            }
        }

      private void DrawCircle(Graphics3D GraphObj)
        {
            //Get the TagInfo of the series
            foreach (Series _Series in TeeChart.Series)
            {
                TagInfo _TagInfo = _TrendService.TrendManager.TagInfos[_Series.Title];

                //Iterate through the Null indexes instead of the whole data to get the points 
                //for drawing the circle
                for (int i = 0; i < _TagInfo.NullIndexes.Count; i++)
                {
                  int _PtXPos = -1;
                  int _PtYPos = -1;
                  Color PtColor;                    //Point Color
                  double xPtVal = -1;
                  double yPtVal = -1;
                  int _CurrentmiSeriesIndex = _TagInfo.NullIndexes[i];

                  if (_CurrentmiSeriesIndex > 0)
                  {
                    if (!_Series.IsNull(_TagInfo.NullIndexes[i] - 1))
                    {

                      xPtVal = _Series[_CurrentmiSeriesIndex - 1].X;
                      yPtVal = _Series[_CurrentmiSeriesIndex - 1].Y;

                      _PtXPos = _Series.CalcXPosValue(xPtVal);
                      _PtYPos = _Series.CalcYPosValue(yPtVal);

                    }

                    PtColor = _Series.Color;
                    //Paint the circle
                    PaintCircle(GraphObj, _PtXPos, _PtYPos, PtColor);
                  }
                  else if (_CurrentmiSeriesIndex < 0) continue;

                  if (_CurrentmiSeriesIndex + 1 == _Series.Count)
                    continue;
                  if (!_Series.IsNull(_CurrentmiSeriesIndex + 1))
                  {
                    xPtVal = _Series[_CurrentmiSeriesIndex + 1].X;
                    yPtVal = _Series[_CurrentmiSeriesIndex + 1].Y;

                    _PtXPos = _Series.CalcXPosValue(xPtVal);
                    _PtYPos = _Series.CalcYPosValue(yPtVal);

                    PtColor = _Series.Color;
                    GraphObj.Pen.Style = System.Drawing.Drawing2D.DashStyle.Solid;
                    GraphObj.Pen.Transparency = 0;
                    PaintCircle(GraphObj, _PtXPos, _PtYPos, PtColor);
                  }
                }
            }
        }

        private void PaintCircle(Graphics3D GraphObj, int xPos, int yPos, Color PtColor)
        {
            GraphObj.Brush.Color = PtColor;
            GraphObj.Brush.Transparency = 100;

            TeeChart.Canvas.Pen.Color = PtColor;
            TeeChart.Canvas.Pen.Width = 1;

            //Subtrating by radius of the circle
            GraphObj.Ellipse(new Rectangle(xPos - 3, yPos - 3, 6, 6));
        }

Hope i am clear.

Re: How to redraw circles drawn using custom drawing?

Posted: Fri Sep 04, 2009 11:02 am
by narcis
Hi Nitin,

Code below works fine for me here without the need of refreshing the chart. Using the AfterDraw event instead of BeforeDrawSeries also works fine. Does this code works fine for you? If the problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;
			tChart1.Legend.CheckBoxes = true;

			for (int i = 0; i < 5; i++)
			{
				Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
				line1.FillSampleValues();
			}

			tChart1.BeforeDrawSeries += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDrawSeries);
		}

		void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			DrawCircles();
		}

		private void DrawCircles()
		{
			foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
			{
				if (s.Visible)
				{
					for (int i = 0; i < s.Count; i++)
					{
						int x = s.CalcXPos(i);
						int y = s.CalcYPos(i);
						tChart1.Graphics3D.Ellipse(x-3, y-3, x+3, y+3);
					}
				}
			}
		}
Thanks in advance.

Re: How to redraw circles drawn using custom drawing?

Posted: Tue Sep 08, 2009 8:05 am
by 9346725
This worked for me as well.
Thanks.