# Calculating the Function Value Using the Calculate Method

## Content



As an alternative to the use of either a code string or events, the programmer may specify an instance of an object that implements C1.Win.C1Chart.ISimpleFunction interface. Such an object must inherit from the interface and implement a public function name, Calculate. The method, [Calculate](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ISimpleFunction.Calculate.html) takes the independent variable (Double) as a parameter and returns the dependent variable (Double).

For the YFunction class objects, the [CustomFunction](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.YFunction.CustomFunction.html) property must be set to the ISimpleFunction implementation object. For the ParametricFunction class object, the [CustomFunctionX](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CustomFunctionX.html) and [CustomFunctionY](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ParametricFunction.CustomFunctionY.html) properties must be set to appropriate objects implementing the ISimpleFunction interface.

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()      
  yf.CustomFunction = New CustomFunction()     
  yf.MinX = -5       
  yf.MaxX = 5       
  yf.LineStyle.Color = Color.DarkGreen        
  yf.LineStyle.Thickness = 3       
  C1Chart1.ChartGroups(0).ChartData.FunctionsList.Add(yf)      
End Sub     
Public Class CustomFunction     
  Implements C1.Win.C1Chart.ISimpleFunction   
  Public Function Calculate(ByVal x As Double) As Double _    
   Implements C1.Win.C1Chart.ISimpleFunction.Calculate    
    Return -x * x * x     ' y = - x*x*x   
  End Function   
End Class
```

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.DarkGreen;      
  yf.LineStyle.Thickness = 2;     
  yf.CustomFunction = new CustomFunction();    
  c1Chart1.ChartGroups[0].ChartData.FunctionsList.Add( yf);     
}     
class CustomFunction : C1.Win.C1Chart.ISimpleFunction     
{     
  public double Calculate( double x)    
  {   
    return -x*x*x; // y = -x*x*x   
  }    
}
```

DOC-DETAILS-TAG-CLOSE

## See Also

[Working with TrendLines](/componentone/docs/win/online-chart2d/chartingdata/workingwithtrendline)