# Calculating the Function Value Using Events

## Content



Instead of adding source code to the [CodeText](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.YFunction.CodeText.html), [CodeTextX](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CodeTextX.html) or [CodeTextY](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CodeTextY.html) 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](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CalculateX.html) and [CalculateY](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CalculateY.html) 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.

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
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);    
}
private void Function_Calculate( object sender, C1.Win.C1Chart.CalculateFunctionEventArgs e)   
{   
  e.Result = e.Parameter * e.Parameter * e.Parameter; // y = x*x*x    
}
```

DOC-DETAILS-TAG-CLOSE

## See Also

[Calculating the Function Value Using the Calculate Method](/componentone/docs/win/online-chart2d/chartingdata/plottingfunctions/calculatingthevaluef/calculatingthefuncti1)