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.
}
}
}
}
Regards,
Avijit