Page 1 of 1

Problem in Override DrawValue method

Posted: Fri Aug 17, 2012 2:25 pm
by 13052809
I have created a custom series classs inheriting from 'FastLine' class. I have over ridden the 'DrawValue' method where I do some custom stuff.
What I am noticing is that my over ride method 'DrawValue' is not getting called for all the points on the plot. I use right click mouse to drag the plot horizonatally. The 'DrawValue' method is not called for the points that are not visible on the plot - they are just left of the visible portion of the plot.

It is important that my custom code gets called for all the points - otherwise the point which just got moved out of the visible plot frame moves and that affects the line connecting that point and the next point which is still visible on the plot.

I am using TeeChart.NET version 3 - Build 3.5.3371.26406

Please let me know what I can do to fix this.

Thanks in advance.

Re: Problem in Override DrawValue method

Posted: Fri Aug 17, 2012 4:07 pm
by 10050769
Hello Sanjay,

Could you please send us your project, because we can try to solve your problem?

Thanks,

Re: Problem in Override DrawValue method

Posted: Fri Aug 17, 2012 8:55 pm
by 13052809
I have attached the project. Compile and run it in the debugger so that you can see the debug outout window for the messages.
First time you should see the out put showing all the indexes from 1 t0 10. As you drag the plot horizontally to the left you can see the indexes go from 2 to 10, then 3 to 10 and so on. The override DrawValue method in my class does not get called for all the points. it only gets called for the visible points on the plot

Re: Problem in Override DrawValue method

Posted: Fri Aug 17, 2012 8:58 pm
by 13052809
I am not sure if the project got uploaded. But here is the code you will need in any windows form application with TChart on the form.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

tChart1.Series.Clear();

SymbolFastLine aSeries = new SymbolFastLine();
double[] xValues = new double[11];

for ( int i = 0; i < 11; i++)
xValues = 36951 + i * 30;


double[] yValues = new double[] { 109, 3, 1, 72, 179, 78, 158, 196, 144, 92, 88 };
aSeries.Add(xValues, yValues);

aSeries.XValues.DateTime = true;

tChart1.Series.Add(aSeries);
}


}

/// <summary>
/// My inherited class
/// </summary>
public class SymbolFastLine : FastLine
{
public override void DrawValue(int index)
{
// store previous value and change the value by 15 days
double prevVal = XValues[index];
XValues[index] += 15;

base.DrawValue(index);

// notice the index value in the debug output window
// it displays 1 to 10 initially but as you drag the plot to the left
// not all index values are displayed as more points go out of scope
// this method is not called for those points
System.Diagnostics.Debug.WriteLine("Index: " + index.ToString());

// store back the prev value
XValues[index] = prevVal;
}

}

Re: Problem in Override DrawValue method

Posted: Mon Aug 20, 2012 9:52 am
by yeray
Hello Sanjay,

The DrawSeries() method calls the CalcFirstLastVisibleIndex() method before the Draw() (all these three methods are at Series.cs). The DrawValue(int index) method you've overridden is called in the Draw() method, that uses the firstVisible and lastVisible points that were calculated before, at CalcFirstLastVisibleIndex().
And I'm afraid these methods can't be overridden, so the only way I see to make this work as you want is to directly modify the sources.

Re: Problem in Override DrawValue method

Posted: Mon Aug 20, 2012 12:54 pm
by 13052809
Can I change the firstVisible and lastVisible value in the override of the 'Draw' method?

so something like

public override void Draw()
{
this.FirstVisible = 0;
this.LastVisible = this.XValues.count - 1;
base.Draw();
}

If this is not possible then would you consider making this change in the future versions? Allow the FirstVisible and LastVisible to be set or some sort of flag like DrawAllPoints - which when set to true will call DrawValue method on all the points and not just visible points.

THanks for your help.

Re: Problem in Override DrawValue method

Posted: Tue Aug 21, 2012 11:33 am
by yeray
Hi Sanjay,

Maybe you could explain why do you want your values to be drawn in a different position to their value.
Why don't you just change the values after populating the series? Ie, after adding the values:

Code: Select all

for (int i = 0; i < aSeries.Count; i++)
{
    aSeries.XValues.Value[i] = aSeries.XValues.Value[i] + 15;
}

Re: Problem in Override DrawValue method

Posted: Tue Aug 21, 2012 3:48 pm
by 13052809
It is difficult to explain without giving a long explanation. It has something to do with sharing the axis with 2/3 different series and some plotting options our users want. Any way, I am going to change my code so that series values are shifted by 15 for good instead of doing it in the override DrawValue method.