Problem in TeeChart.Axes.Bottom.CalcXPosValue(double)

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Problem in TeeChart.Axes.Bottom.CalcXPosValue(double)

Post by Avijit » Wed Nov 18, 2009 11:20 am

Hi,
I am trying to get the pos value of the x axis usin g the below call -

TeeChart.Axes.Bottom.CalcXPosValue(dSTime);
but it is returing me zero.

I am doing this -

Code: Select all


      public void Activate()
      {
          //do the initial Drawing.
          if (Data.Tags.Count > 0)
            RedrawTrends();
      }

      public void RedrawTrends()
      {
              //clear the existing series.
            if (TeeChart.Series.Count > 0)
            {
              TeeChart.Series.Clear();
              Count = 0;
            }

            //It creates the Series if Series is not there 
            //and add the series to Series Collection of teechart
            DrawTrends();   
     
            //Now i want to draw the rectacgles on top of the UI
            DrawMarkRanges(Data, ViewType);
     }
      private void DrawMarkRanges(List<TagInfo> TagInfosUpdated, string vcMarkType)
      {
        Rectangle _Rect = TeeChart.Chart.ChartRect;
        //Get the width of the labels for veritcal axis
        int iLeftAxisLabelWidth = (TeeChart.Axes.Left.Labels.Visible == true) ? TeeChart.Axes.Left.Labels.Right : 0;


        double _ColumnWidth = (TeeChart.Chart.Width - iLeftAxisLabelWidth) / iVerLines;
        double _RowHeight = ((double)(_Rect.Height) / (double)(iHorLines));

        ForNormalizedScale = ScaleType == TrendScale.Normalized ? true : false;

        //Calculate the top value to start
        foreach (TagInfo _TagInfo in TagInfosUpdated)
        {
          IRangeHolder _RangeHolder = _TagInfo.Tag.GetRangeHolder();
          foreach (IRange _Range in _RangeHolder.Ranges)
          {
            if (_Range.RangeMarkType == vcMarkType && ForNormalizedScale)
            {
              Series _Series = TeeChart.Series.WithTitle(_TagInfo.Tag.Name);
              DateTime StartTime = _Range.StartTime;
              DateTime EndTime = _Range.EndTime;
              double dSTime = _TagInfo.Tag.GetTimeSeriesIndex(StartTime.ToOADate());
              double dETime = _TagInfo.Tag.GetTimeSeriesIndex(EndTime.ToOADate());
              _StartIndexMouseLoc = TeeChart.Axes.Bottom.CalcXPosValue(dSTime);  //Here it is returning 0 even though dSTime is a valid value
             _EndIndexMouseLoc = TeeChart.Axes.Bottom.CalcXPosValue(dETime);     //Here it is returning 0 even though dETime is a valid value

              int iLeft = _StartIndexMouseLoc > _EndIndexMouseLoc ? _EndIndexMouseLoc : _StartIndexMouseLoc; ;
              int iWidth = _StartIndexMouseLoc > _EndIndexMouseLoc ? _StartIndexMouseLoc - _EndIndexMouseLoc : _EndIndexMouseLoc - _StartIndexMouseLoc;
              int iTop = _Series.CalcYPosValue(_Series.MaxYValue());
              int iHeight = _Series.CalcYPosValue(_Series.MinYValue()) - iTop;
              PaintRangeMark(iLeft, iWidth, iTop, iHeight, vcMarkType);
            }
            else if(_Range.RangeMarkType == vcMarkType && !ForNormalizedScale)   //For Single and Multiple scale
            {
              DateTime StartTime = _Range.StartTime;
              DateTime EndTime = _Range.EndTime;
              double dSTime = _TagInfo.Tag.GetTimeSeriesIndex(StartTime.ToOADate());
              double dETime = _TagInfo.Tag.GetTimeSeriesIndex(EndTime.ToOADate());
              _StartIndexMouseLoc = TeeChart.Axes.Bottom.CalcXPosValue(dSTime);     //Here it is returning 0 even though dSTime is a valid value
              _EndIndexMouseLoc = TeeChart.Axes.Bottom.CalcXPosValue(dETime);        //Here it is returning 0 even though dETime is a valid value

              //We can draw rectangle of our own here
              int iLeft = _StartIndexMouseLoc > _EndIndexMouseLoc ? _EndIndexMouseLoc : _StartIndexMouseLoc; 
              int iWidth = _StartIndexMouseLoc > _EndIndexMouseLoc ? _StartIndexMouseLoc - _EndIndexMouseLoc : _EndIndexMouseLoc - _StartIndexMouseLoc;
              int iTop = _Rect.Top;
              int iHeight = _Rect.Bottom - _Rect.Top;
              PaintRangeMark(iLeft, iWidth, iTop, iHeight, vcMarkType);         //Paintinng the rectangle iLeft and i Width is coming as 0.
            }
          }
        }
      }

Let me know if i am doing anything wrong.

Regards,
Avijit

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Problem in TeeChart.Axes.Bottom.CalcXPosValue(double)

Post by Sandra » Fri Nov 20, 2009 12:22 pm

Hello Avijit,
I am trying to get the pos value of the x axis usin g the below call -

TeeChart.Axes.Bottom.CalcXPosValue(dSTime);
but it is returing me zero.
If you want to calculate a position of axes, first you are sure chart has been painted. Please check that chart is painted. If problem not solved or this is not the problem please, you could send us a simple project, because we can reproduce issue here?


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Problem in TeeChart.Axes.Bottom.CalcXPosValue(double)

Post by Avijit » Mon Nov 23, 2009 11:37 am

Hi,
May be you are right. I have added one flag for checking if the chart is drawn. Then i have added the same code for getting the axis pos value at AfterDraw event. Now it is returning the correct value.
But problem is i cant keep all these calculations code in the AfterDraw event as we have huge data to handle.
Please let me know one thing - i have added the data series with the teechart. Called the draw function. Then how come even before drawing the chart it goes to the calculate pos part? Please see the code flow below -

Activate()
{
DrawTrends();
MarkingUpdated();
}
DrawTrends()
{
//Create the data series and add the Series to the SeriesCollection
TeeChart.Refresh();
}
MarkingUpdated()
{
//Calculate the axis position here and do something
}

With the above flow the TeeChart should be drawn after the DrawTrends() function. Correct?
Then why in MarkingUpdated() fuction i am not getting the Axis pos value??

Regards,
Avijit

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Problem in TeeChart.Axes.Bottom.CalcXPosValue(double)

Post by Sandra » Tue Nov 24, 2009 10:23 am

Hello Avijit,

I think problem is when you do refresh. I propose that remove the code there are in AfterDraw() event and you add this code after call to tChart1.Draw(). If you do this, code will not be run every time that you be paint chart and pos value will be calculated correctly.

Please see, modified of your code:

Code: Select all

Activate()
{
DrawTrends();
MarkingUpdated();
}
DrawTrends()
{
//Create the data series and add the Series to the SeriesCollection
TeeChart1.Draw();
}
MarkingUpdated()
{
//Calculate the axis position here and do something
}
Please, check that next code works fine. If you still have problems, please you could send us a simple project that we can run and reproduce here?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply