-1

I'm wanting to take my Tchart (connected to a database query through a clientdataset) and draw a best fit line onto it. To do this (unless there is a built in method) I'm planning to work out the gradient of the first and the last data entries. How do I grab their coordinates to calculate the gradient for the line equation? This is what i want in psuedocode:

FirstXAxis := Datapoint[0].XAxis; 
LastXAxis := Datapoint[LastEntry].XAxis; 

I know this isn't strictly a line of best fit but I couldn't think of anything else (I'm new to graphical delphi and databases). How do I find LastEntry?

Please help me out, Toby

TobyFox1997
  • 71
  • 1
  • 5
  • 1
    Why not get the values from the clientdataset? Plus, you cannot get the best fit line using only the first and last data values, you mus use them all. – crefird Feb 06 '15 at 21:13
  • How? And ok haha using the CDS would probably be easier. – TobyFox1997 Feb 06 '15 at 21:24
  • There are examples with TeeChart (or available from their web site) showing how to chart directly from a dataset. Also, the datapoints are in an array, so you can use `DataPoint[High(DataPoint)]` to find the last entry. – Ken White Feb 06 '15 at 21:33
  • when you say 'Datapoint' what is this? An attribute of the chart? – TobyFox1997 Feb 06 '15 at 22:35
  • 1
    Can you define "best fit"? If you can't do that then nobody can implement anything, not even you! What you are currently proposing is not "best fit". – David Heffernan Feb 08 '15 at 19:35

1 Answers1

1

You might be interested in the curve fitting function (TCurveFittingFunction). You'll find examples at All Features\Welcome!\Functions\Extended\Curve fitting in the new features demo available at the TeeChart program group created by the Pro binary installers. Examples on how to calculate line gradient are also included.

Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47