示例#1
0
        private void UpdateChartStats()
        {
            if (DataPoints == null || DataPoints.Count == 0) return;
            double min = DataPoints[0], max = DataPoints[0];

            // For trending
            double xxSum = 0, xySum = 0, xAxisValuesSum = 0, yAxisValuesSum = 0;
            Sum = Math.Abs(DataPoints[0]);

            for (int i = 1; i < DataPoints.Count; i++)
            {
                double value = DataPoints[i];
                if (value < min) min = value;
                if (value > max) max = value;
                Sum += Math.Abs(value);
                xySum += value * (i + 1);
                xxSum = value * value;
                yAxisValuesSum += value;
                xAxisValuesSum += i + 1;
            }


            double slope = 0, intercept = 0, start = 0, end = 0;
            try
            {
                slope = ((DataPoints.Count * xySum) - (xAxisValuesSum * yAxisValuesSum)) /
                    ((DataPoints.Count * xxSum) - (xAxisValuesSum * xAxisValuesSum));
            }
            catch (DivideByZeroException) { }
            intercept = (yAxisValuesSum - (slope * xAxisValuesSum)) / DataPoints.Count;
            start = Math.Max(0, (slope * DataPoints[0]) + intercept);
            end = (slope * DataPoints[DataPoints.Count - 1]) + intercept;
            this.TrendInfo = new TrendInfo(slope, intercept, start, end);

            if(double.IsNaN(DataPointMaxValue))
                DataPointMaxValue = max;
            if(double.IsNaN(DataPointMinValue))
                DataPointMinValue = min;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the MicroChartRenderInfo structure.
        /// </summary>
        /// <param name="dataPoints"></param>
        /// <param name="graphics"></param>
        /// <param name="chartWidth"></param>
        /// <param name="chartHeight"></param>
        public MicroChartRenderInfo(List<double> dataPoints, Graphics graphics, int chartWidth, int chartHeight, double dataMax, double dataMin)
        {
            DataPoints = dataPoints;
            Graphics = graphics;
            ChartWidth = chartWidth;
            ChartHeight = chartHeight;

            MicroChartHotPoints = null;
            DataPointMaxValue = dataMax;
            DataPointMinValue = dataMin;
            Sum = 0;
            TrendInfo = new TrendInfo();

            UpdateChartStats();
        }