I have an existing TChart object "LChart". It's a component on a form.
I have an existing TChartSeries "LSeries". It's created at runtime based on a series type string "LSeriesType" like so:
Code: Select all
var
C : TRttiContext;
T : TRttiInstanceType;
V : TValue;
LSeries: TChartSeries;
begin
C := TRttiContext.Create;
try
T := (C.FindType('VCLTee.Series.'+LSeriesType) as TRttiInstanceType);
if assigned(T) then begin
V := T.GetMethod('Create').Invoke(T.metaClassType,[Visualisation]);
LSeries := V.AsObject as TChartSeries;
end
else
raise Exception.Create(format('Could not create %s graph type', ['VCLTee.Series.'+LSeriesType]));
finally
C.Free;
end;
LChart.AddSeries(LSeries);
end;
initialization
// Reference every series type so that they get linked into the exe and can be found at runtime by TRttiContext.FindType
TBarSeries.ClassName;
TAreaSeries.ClassName;
TBarSeries.ClassName;
TFastLineSeries.ClassName;
THorizAreaSeries.ClassName;
THorizBarSeries.ClassName;
THorizLineSeries.ClassName;
TLineSeries.ClassName;
TPieSeries.ClassName;
TPointSeries.ClassName;
Now I want to add a Trend Line series to the chart. I've added this additional code:
Code: Select all
var
LTrendFunction: TTrendFunction;
LLineSeries: TLineSeries;
begin
LTrendFunction := TTrendFunction.Create(LChart);
LTrendFunction.Period := 3;
LLineSeries := LChart.AddSeries(TLineSeries) as TLineSeries;
LLineSeries.SetFunction(LTrendFunction);
LLineSeries.Color := TColor(fdqVisualisationSeries.FieldByName('TrendLineColor').AsInteger);
LLineSeries.Title := 'Trend';
LLineSeries.DataSource := LSeries; // LSeries has no data at this point
LLineSeries.XValues.Name := LSeries.XValues.Name;
LLineSeries.XValues.Order := LSeries.XValues.Order;
LLineSeries.YValues.Name := LSeries.YValues.Name;
LLineSeries.YValues.Order := LSeries.YValues.Order;
end;
I am not seeing the Trend Line series displayed at all.
Can you please let me know what I might be doing wrong here?
Many thanks
Mark