Problem in Override DrawValue method

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Sanjay
Newbie
Newbie
Posts: 8
Joined: Mon Mar 16, 2009 12:00 am

Problem in Override DrawValue method

Post by Sanjay » Fri Aug 17, 2012 2:25 pm

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.

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

Re: Problem in Override DrawValue method

Post by Sandra » Fri Aug 17, 2012 4:07 pm

Hello Sanjay,

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

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

Sanjay
Newbie
Newbie
Posts: 8
Joined: Mon Mar 16, 2009 12:00 am

Re: Problem in Override DrawValue method

Post by Sanjay » Fri Aug 17, 2012 8:55 pm

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

Sanjay
Newbie
Newbie
Posts: 8
Joined: Mon Mar 16, 2009 12:00 am

Re: Problem in Override DrawValue method

Post by Sanjay » Fri Aug 17, 2012 8:58 pm

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;
}

}

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem in Override DrawValue method

Post by Yeray » Mon Aug 20, 2012 9:52 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Sanjay
Newbie
Newbie
Posts: 8
Joined: Mon Mar 16, 2009 12:00 am

Re: Problem in Override DrawValue method

Post by Sanjay » Mon Aug 20, 2012 12:54 pm

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.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem in Override DrawValue method

Post by Yeray » Tue Aug 21, 2012 11:33 am

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;
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Sanjay
Newbie
Newbie
Posts: 8
Joined: Mon Mar 16, 2009 12:00 am

Re: Problem in Override DrawValue method

Post by Sanjay » Tue Aug 21, 2012 3:48 pm

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.

Post Reply