Esempio n. 1
0
                public virtual void UpdateDataMinMax(DataTable table)
                {
                    if (Chart.Plot.XAxis1 == null)
                    {
                        return;
                    }
                    const double PWR      = 2;
                    double       avg      = 0;
                    double       stdDev   = 0;
                    double       min      = double.MaxValue;
                    double       max      = double.MinValue;
                    double       dev      = 0;
                    int          start    = Chart.GetDataIndex(Chart.Plot.XAxis1.WorldMin);
                    int          end      = Chart.GetDataIndex(Chart.Plot.XAxis1.WorldMax);
                    int          step     = Math.Max((end - start) / 8192, 1);
                    int          numSteps = (((end - start) + (step - 1)) / step);
                    int          count    = 0;

                    if (numSteps > 0)
                    {
                        // Calculate the average, std dev, min, and max
                        for (int i = start; (table.Rows.Count > i) && (i <= end); i += step)
                        {
                            double val = NPlot.Utils.ToDouble(table.Rows[i][Expression]);
                            if (double.IsNaN(val))
                            {
                                continue;
                            }
                            avg += (val - avg) / ++count;
                            dev += Math.Pow((val - avg), 2);
                            min  = (val < min) ? val : min;
                            max  = (val > max) ? val : max;
                        }

                        // Set the chart to show the entire data range
                        PlotYAxis.WorldMin = avg - ((avg - min) * 1.1);
                        PlotYAxis.WorldMax = avg + ((max - avg) * 1.1);

                        // When plotting time, hide some of the outliers
                        if (Chart.XAxis.Equals("Time"))
                        {
                            dev = Math.Sqrt(dev / count);
                            PlotYAxis.WorldMin = Math.Max(PlotYAxis.WorldMin, avg - (dev * 6));
                            PlotYAxis.WorldMax = Math.Min(PlotYAxis.WorldMax, avg + (dev * 6));
                        }
                    }
                }
Esempio n. 2
0
                public virtual void UpdateDataMinMax(DataTable table)
                {
                    if (Chart.Plot.XAxis1 == null)
                    {
                        return;
                    }
                    const double PWR      = 2;
                    double       avg      = 0;
                    double       stdDev   = 0;
                    double       min      = double.MaxValue;
                    double       max      = double.MinValue;
                    double       dev      = 0;
                    int          start    = Chart.GetDataIndex(Chart.Plot.XAxis1.WorldMin);
                    int          end      = Chart.GetDataIndex(Chart.Plot.XAxis1.WorldMax);
                    int          step     = Math.Max((end - start) / 4096, 1);
                    int          numSteps = (((end - start) + (step - 1)) / step);
                    int          count    = 0;

                    if (numSteps > 0)
                    {
                        // Calculate the average first
                        for (int i = start; i <= end; i += step)
                        {
                            double val = NPlot.Utils.ToDouble(table.Rows[i][Expression]);
                            if (double.IsNaN(val))
                            {
                                continue;
                            }
                            avg += (val - avg) / ++count;
                            dev += Math.Pow((val - avg), 2);
                            min  = (val < min) ? val : min;
                            max  = (val > max) ? val : max;
                        }
                        dev = Math.Sqrt(dev / count);
                        PlotYAxis.WorldMin = Math.Max(avg - ((avg - min) * 1.1), avg - (dev * 4));
                        PlotYAxis.WorldMax = Math.Min(avg + ((max - avg) * 1.1), avg + (dev * 4));
                    }
                }