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 takes the independent variable (Double) as a parameter and returns the dependent variable (Double).
For the YFunction class objects, the CustomFunction property must be set to the ISimpleFunction implementation object. For the ParametricFunction class object, the CustomFunctionX and CustomFunctionY properties must be set to appropriate objects implementing the ISimpleFunction interface.
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
· 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.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
}
}
· Delphi
type
CustomFunction = class(TObject, C1.Win.C1Chart.ISimpleFunction)
public
function Calculate(x: double): double;
end;
implementation
function CustomFunction.Calculate(x: double): double;
begin
Result := -x*x*x; // y = -x*x*x
end;
procedure 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.DarkGreen;
yf.LineStyle.Thickness := 2;
yf.CustomFunction := CustomFunction.Create;
C1Chart1.ChartGroups[0].ChartData.FunctionsList.Add(yf);
end;
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |