Page 1 of 1
VC++ and custom functions
Posted: Fri Sep 21, 2007 2:34 pm
by 9080145
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
Posted: Fri Sep 21, 2007 2:44 pm
by narcis
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!
Posted: Fri Sep 21, 2007 3:32 pm
by 9080145
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
Posted: Fri Sep 21, 2007 3:39 pm
by narcis
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.
Posted: Fri Sep 21, 2007 3:47 pm
by 9080145
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
Posted: Mon Sep 24, 2007 7:26 am
by narcis
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
Posted: Mon Sep 24, 2007 7:45 am
by 9080145
Hi - thanks for the sample, but I'm using TeeChart 5 under VC++. Do you have a sample for this environment?
Rgds,
Sacha
Posted: Mon Sep 24, 2007 8:33 am
by narcis
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.