Page 1 of 1

Draw Trend Line to Chart Extents

Posted: Mon Nov 09, 2015 11:04 am
by 9339158
Hi Guys

I am plotting a linear trend line with this:

Code: Select all

TrendFunction trendFunction =new TrendFunction();

trendLine = new Line(chart.Chart) { Function = trendFunction, DataSource = series };
Which is working nicely but the line is only drawn to the extents of the data in the series.

Is it possible for the trend line to continue so that either end touches the axes/chart extents? Similar to plotting with slope and Y intercept as opposed to a start and end point?

Many Thanks
J

Re: Draw Trend Line to Chart Extents

Posted: Tue Nov 10, 2015 9:02 am
by Christopher
Hello!

There's a similar question asked in ActiveX here.

If the given answer is not enough detail for you, please let us know and we can get a quick example together for you.

Re: Draw Trend Line to Chart Extents

Posted: Tue Nov 10, 2015 9:44 am
by 9339158
Hi Christopher

Thank you for getting back to me.

I already have some maths to calculate the slope and intercept - so that's all okay.

My reason for using TrendFunction is to move away from our own maths and rely on the TeeChart library - so it seems a shame to use a combination of both.

Please can you advise me further or create a sample on how best to achieve the trend line so it continues to draw beyond the data to the extents of the chart/to Y axis?

Whether a combination of TrendFunction and some of our own maths - perhaps to calculate and add some start/end points to the results of TrendFunction?

Or perhaps just go back to using our own maths?

Ideally I was hoping to stick with just using TrendFunction and there be a property somewhere that says "Continue Line".

Many Thanks
J

Re: Draw Trend Line to Chart Extents

Posted: Tue Nov 10, 2015 5:12 pm
by Christopher
You're welcome J.

There is no ContinueLine() method at present, but here is my attempt at one:

Code: Select all

    private void InitializeChart()
    {
      Line line1 = null, line2 = null;

      Action ContinueLine = () =>
      {
        SeriesXYPoint point1 = line2[0];
        SeriesXYPoint point2 = line2[1];

        double diffX = point1.X - point2.X;
        double diffY = point1.Y - point2.Y;
        double diff = diffX / diffY;

        SeriesXYPoint point3 = new SeriesXYPoint(line2, line2.Count - 1);
        point3.X = 2000;
        point3.Y = 2000 * diff;

      };

      tChart1.Aspect.View3D = false;
      line1 = new Line(tChart1.Chart);
      line1.FillSampleValues(1000);

      line2 = new Line(tChart1.Chart);
      TrendFunction trend = new TrendFunction();
      trend.UseDecimals = true;
      line2.Function = trend;
      line2.DataSource = line1;

      ContinueLine();
    }
I hope you find this code of some use.

Re: Draw Trend Line to Chart Extents

Posted: Fri Nov 13, 2015 3:58 pm
by 9339158
Thank you - your code sample helped, particularly using SeriesXYPoint to change the line points.

I took a different approach with the maths:

As we know the X values of the new points (i.e. the right or left edge of the chart) I used the slope and Y intercept to calculate the Y values.

y = mx + c