VC++ and custom functions

TeeChart for ActiveX, COM and ASP
Post Reply
sms
Newbie
Newbie
Posts: 4
Joined: Fri Dec 05, 2003 5:00 am
Contact:

VC++ and custom functions

Post by sms » Fri Sep 21, 2007 2:34 pm

Hi,

I'm using TeeChart 5 under VC8 and would be grateful for some help in defining and using custom functions. I have two FastLine series, and would like to add a third series, which is (series 1 - series 2) * 100. I add points to the series like this:

XValues.Create(VT_R8, 1, numElements);
YValues.Create(VT_R8, 1, numElements);

[add points to the arrays]

m_Graph.Series(seriesId).AddArray(index, YValues, XValues);

Do you have any sample code that shows how to create a third series and tie it to series1 and series2 using the relationship (series 1 - series 2) * 100?

Many thanks,

Sacha

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Sep 21, 2007 2:44 pm

Hi Sacha,

Yes, you can do something like this:

Code: Select all

	long series1;	
	series1 = m_Chart1.AddSeries(scLine);
	m_Chart1.Series(series1).FillSampleValues(10);

	long series2;
	series2 = m_Chart1.AddSeries(scLine) ;
	m_Chart1.Series(series2).FillSampleValues(10);

	long series3;
	series3 = m_Chart1.AddSeries(scLine);

	for	(int i=0; i< m_Chart1.Series(series1).GetCount(); i++)
	{

		m_Chart1.Series(series3).AddXY(m_Chart1.Series(series1).GetXValues().GetValue(i),
									(m_Chart1.Series(series1).GetYValues().GetValue(i)-
									m_Chart1.Series(series2).GetYValues().GetValue(i))*100,"",clTeeColor);
	}
Hope this helps!
Best Regards,
Narcís Calvet / 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

sms
Newbie
Newbie
Posts: 4
Joined: Fri Dec 05, 2003 5:00 am
Contact:

Post by sms » Fri Sep 21, 2007 3:32 pm

Hi Narcis,

Thanks for the sample. I was thinking more of using the custom function features in TeeChart to set up a relationship between two series. This would hopefully enable me to only have to populate series 1 and 2, and then the third series would be automatically populated. This is the most convenient implementation for my application.

Additionally, the graphs may not have the same X values. For instance:

Series 1:
X Y
1 1
2 2
3 3
4 4

Series 2:
X Y
0.5 6
1.7 7
1.9 8
2.9 9

Is this handled by the Function feature in TeeChart?

Kind regards,

Sacha

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Sep 21, 2007 3:39 pm

Hi Sacha,

This supported in newer TeeChart Pro ActiveX versions (current version is number 8 ) where y=f(x) function is included. I'd recommend you to have a look at the fully functional evaluation version here. It includes examples of mentioned function usage.

Code: Select all

Additionally, the graphs may not have the same X values.
In that case you should decide what to do with them if processing them as it's done with Y values, add a point for each X value in both series, etc.
Best Regards,
Narcís Calvet / 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

sms
Newbie
Newbie
Posts: 4
Joined: Fri Dec 05, 2003 5:00 am
Contact:

Post by sms » Fri Sep 21, 2007 3:47 pm

Hi Narcís,

I see - thanks. I might be able to force both series to have the same X values. In this case, could you provide some sample code to use a custom function?

KR,

Sacha

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Sep 24, 2007 7:26 am

Hi Sacha,

Below there's an example of custom function available in TeeChart Pro v8 ActiveX.

Code: Select all

Private Sub UpdateChart()
  'Force the recalculation function
  TChart1.Series(0).FunctionType.BeginUpdate
  TChart1.Series(0).FunctionType.EndUpdate
End Sub

Private Sub Form_Load()
  UpdateChart
End Sub

Private Sub TChart1_OnFunctionCalculate(ByVal SeriesIndex As Long, ByVal X As Double, Y As Double)
  Y = Sin(X / 10)
End Sub
Best Regards,
Narcís Calvet / 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

sms
Newbie
Newbie
Posts: 4
Joined: Fri Dec 05, 2003 5:00 am
Contact:

Post by sms » Mon Sep 24, 2007 7:45 am

Hi - thanks for the sample, but I'm using TeeChart 5 under VC++. Do you have a sample for this environment?

Rgds,

Sacha

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Sep 24, 2007 8:33 am

Hi Sacha,

As I told you before, this function is not available in v5. Its usage would be exactly the same in VC++ just changing syntax is needed.
Best Regards,
Narcís Calvet / 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