Average between 2 points

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
andyb
Newbie
Newbie
Posts: 8
Joined: Tue Feb 01, 2005 5:00 am

Average between 2 points

Post by andyb » Thu Mar 30, 2006 1:48 pm

Hello again,

I would like to be able to work out the average between 2 points, indicated on a line graph using (maybe) two x-axis colorbands.

Could you recommend the best way to do this?

thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 30, 2006 2:10 pm

Hi andyb,

Have you tried using an average function? You'll find further information at Tutorial 7 - Working with Functions. You'll find TeeChart tutorials at its program group.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

andyb
Newbie
Newbie
Posts: 8
Joined: Tue Feb 01, 2005 5:00 am

Post by andyb » Thu Mar 30, 2006 2:32 pm

Hi Narcis,

Thanks for your reply.

I have used an average function, but I can only get it to work over the distance of the entire chart.

I'd like to be able to drag the start and end points for the funtion anywhere over the x-axis. Is there a way to do this?

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 30, 2006 3:43 pm

Hi andyb,

Then you can try doing something like this:

Code: Select all

    private double OldStart,OldEnd;

    private void Form1_Load(object sender, EventArgs e)
    {
      line1.FillSampleValues();

      colorBand1.Start = 5;
      colorBand1.End = line1.Count -5;

      OldStart=colorBand1.Start;
      OldStart=colorBand1.End;

      CalculateAverageRange(colorBand1.Start, colorBand1.End);
    }

    private void CalculateAverageRange(double start, double end)
    {
      Steema.TeeChart.Styles.Line source = new Steema.TeeChart.Styles.Line();

      for (int i=0; i <line1.Count; ++i)
      {
        if ((line1.XValues[i] >= start) && (line1.XValues[i] <= end))
          source.Add(line1.XValues[i],line1.YValues[i]);
      }      

      if (tChart1.Series.Count == 1)
      {
        Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      }

      Steema.TeeChart.Functions.Average average1 = new Steema.TeeChart.Functions.Average();
      tChart1[tChart1.Series.Count - 1].Function = average1;

      tChart1[tChart1.Series.Count - 1].DataSource = source;
      //tChart1[tChart1.Series.Count - 1].Function.Period = 2;
      tChart1[tChart1.Series.Count - 1].CheckDataSource(); 
    }

    private void tChart1_MouseMove(object sender, MouseEventArgs e)
    {
      if ((colorBand1.Start!=OldStart) || (colorBand1.End!=OldEnd))
      {
        CalculateAverageRange(colorBand1.Start, colorBand1.End);
        OldStart=colorBand1.Start;
        OldEnd=colorBand1.End;
      }
    }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply