Page 1 of 1

Average between 2 points

Posted: Thu Mar 30, 2006 1:48 pm
by 8128839
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.

Posted: Thu Mar 30, 2006 2:10 pm
by narcis
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.

Posted: Thu Mar 30, 2006 2:32 pm
by 8128839
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

Posted: Thu Mar 30, 2006 3:43 pm
by narcis
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;
      }
    }