ComponentOne Chart for .NET (2.0) Search HelpCentral 

Calculating the Function Value Using Events

Instead of adding source code to the CodeText, CodeTextX or CodeTextY properties, an event delegate can be used to specify an event method to calculate the appropriate function value.

When using event delegates, the function value is calculated in event CalculateY for the YFunction class objects. For ParametricFunction class objects, two events, CalculateX and CalculateY must be set, one for each calculated coordinate. Non-null event delegates indicate that the event should be used to calculate the corresponding function value, even if the corresponding CodeText property is also specified in either the YFunction or ParametricFunction class objects. In order to use events, the programmer must provide the appropriate event handlers.

·      Visual Basic

Private Sub Button_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles Button.Click

  Dim yf As C1.Win.C1Chart.YFunction = New C1.Win.C1Chart.YFunction()

  AddHandler yf.CalculateY, AddressOf Function_Calculate

  yf.MinX = -5

  yf.MaxX = 5

  yf.LineStyle.Color = Color.DarkBlue

  yf.LineStyle.Thickness = 3

 

  C1Chart1.ChartGroups(0).ChartData.FunctionsList.Add(yf)

End Sub

 

Private Sub Function_Calculate(ByVal sender As Object, _
 ByVal e As C1.Win.C1Chart.CalculateFunctionEventArgs)

  e.Result = e.Parameter * e.Parameter * e.Parameter    ' y = x*x*x

End Sub

·      C#

private void button_Click(object sender, System.EventArgs e)

{

  C1.Win.C1Chart.YFunction yf = new C1.Win.C1Chart.YFunction();

 

  yf.MinX = -5;

  yf.MaxX = 5;

  yf.LineStyle.Color = Color.DarkBlue;

  yf.LineStyle.Thickness = 2;

  yf.CalculateY += new C1.Win.C1Chart.CalculateFunctionEventHandler( Function_Calculate);

 

  c1Chart1.ChartGroups[0].ChartData.FunctionsList.Add( yf);

}

 

void Function_Calculate( object sender, C1.Win.C1Chart.CalculateFunctionEventArgs e)

{

  e.Result = e.Parameter * e.Parameter * e.Parameter; // y = x*x*x

}

·      Delphi

procedure TWinForm1.FuncCalculate(sender: System.Object;

  e: C1.Win.C1Chart.CalculateFunctionEventArgs);

begin

  e.Result := e.Parameter * e.Parameter * e.Parameter; // y = x*x*x

end;

 

procedure TWinForm1.Button_Click(sender: System.Object; e: System.EventArgs);

var

  yf: C1.Win.C1Chart.YFunction;

 

begin

  yf := C1.Win.C1Chart.YFunction.Create;

 

  yf.MinX := -5;

  yf.MaxX := 5;

  yf.LineStyle.Color := Color.DarkBlue;

  yf.LineStyle.Thickness := 2;

  Include(yf.CalculateY, Self.FuncCalculate);

 

  C1Chart1.ChartGroups[0].ChartData.FunctionsList.Add(yf);

end;


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.