Page 1 of 1

StdDeviation with Offset?

Posted: Fri Mar 27, 2009 2:01 pm
by 13049497
Hello,

i use a fastline (f1) with a custom axis and a second fastline (f2) with datasource = f1. The second one has also the function stddeviation set. In that case, the line f2 has also the same axis like f1 and is automaticly shown at the bottom of the chart. now i want to show f2 relative to the average of f1. For example now:

|
|---------------------- f1
|
|
|
|
|----------------------- f2 (stddev)
|________________

wanted:

|----------------------- f2 (stddev)
|---------------------- f1
|----------------------- f2 (stddev)
|
|
|
|
|________________

The value of f2 is correct, but must be shown relatively to the average of f1 so you can see the relationship of f1 and f2. How can i achieve this without to calculate the stdev for my own :)?

Thanks in advance!

Posted: Fri Mar 27, 2009 3:46 pm
by narcis
Hi AIS,

I'm not sure about what you are trying to achieve but you can calculate Average and Std. Deviation for datasource series, for example:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			Steema.TeeChart.Styles.FastLine fastLine1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
			fastLine1.Title = "Data";
			fastLine1.FillSampleValues();

			Steema.TeeChart.Styles.FastLine avgLine = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
			avgLine.Title = "Average";
			Steema.TeeChart.Functions.Average average1 = new Steema.TeeChart.Functions.Average();
			avgLine.Function = average1;
			avgLine.DataSource = fastLine1;

			Steema.TeeChart.Styles.FastLine stdDevLine = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
			stdDevLine.Title = "Std. Deviation";
			Steema.TeeChart.Functions.StdDeviation stdDev1 = new Steema.TeeChart.Functions.StdDeviation();
			stdDevLine.Function = stdDev1;
			stdDevLine.DataSource = fastLine1;
		}
If that's not what you need please provide more information. An image might be helpful. You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Mon Mar 30, 2009 6:21 am
by 13049497
Hi Narcís,

for better understanding what i want to do:
Image


Image

You can see, that the std. deviation in the second picture is not at the bottom of the chart like in the first one. The two lines are avg-std.dev and avg+std.dev. Is it possible to combine the functions or set an offset for std.dev. to achieve this?

Thanks!

Posted: Mon Mar 30, 2009 5:23 pm
by narcis
Hi AIS,

In that case you can do this:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;

      Steema.TeeChart.Styles.FastLine fastLine1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      fastLine1.Title = "Data";
      fastLine1.FillSampleValues();

      Steema.TeeChart.Styles.FastLine avgLine = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      avgLine.Title = "Average";
      Steema.TeeChart.Functions.Average average1 = new Steema.TeeChart.Functions.Average();
      avgLine.Function = average1;
      avgLine.DataSource = fastLine1;

      Steema.TeeChart.Styles.FastLine stdDevLine = new Steema.TeeChart.Styles.FastLine();
      stdDevLine.Title = "Std. Deviation";
      Steema.TeeChart.Functions.StdDeviation stdDev1 = new Steema.TeeChart.Functions.StdDeviation();
      stdDevLine.Function = stdDev1;
      stdDevLine.DataSource = fastLine1;

      Steema.TeeChart.Styles.FastLine avgPlusStdDev = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      Steema.TeeChart.Styles.FastLine avgLessStdDev = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

      for (int i = 0; i < avgLine.Count; i++)
      {
        avgPlusStdDev.Add(avgLine.XValues[i], avgLine.YValues[i] + stdDevLine.YValues[i]);
        avgLessStdDev.Add(avgLine.XValues[i], avgLine.YValues[i] - stdDevLine.YValues[i]);
      }
    }

Posted: Tue Mar 31, 2009 8:09 am
by 13049497
Hi Narcís,

yes, this is a solution but with a bad performance. In our case we often have 5-10 series each with over 80000 points (x,y) and an own average and st.dev. This solution costs a lot of performance when the avg period is small (e.g. 1), because we must loop all average points. Nevertheless i will use it ;)

Thanks anyway for your quick response!

Bye!

Posted: Tue Mar 31, 2009 8:34 am
by narcis
Hi AIS,

You could try applying hints in the Real-time Charting article here:

http://www.teechart.net/reference/articles/index.php

Posted: Tue Mar 31, 2009 11:02 am
by 13049497
Hi Narcís,

this article is already implemented :)
BTW: Our customer would like to see points instead of fastlines therefore not all optimizations are possible.. :(