Exemplo n.º 1
0
        public static void DrawLineChart(ref List <InputTxtData> data,
                                         ref List <int> filteredDataValues,
                                         ref Graphics g,
                                         TimeSpan statingTime,
                                         TimeSpan endingTime,
                                         int MinValue,
                                         int MaxValue,
                                         int imageWidth,
                                         int imageHeight,
                                         Pen currentPen)
        {
            long         durationInSeconds = (long)(endingTime.TotalSeconds - statingTime.TotalSeconds);
            float        yScale            = (float)imageHeight / (float)MaxValue;
            float        xScale            = (float)imageWidth / (float)durationInSeconds;
            InputTxtData previousData      = null;
            int          previousValue     = MinValue;

            for (int i = 0; i < data.Count; i++)
            {
                if (previousData != null)
                {
                    g.DrawLine(currentPen, (float)(previousData.Timestamp - statingTime).TotalSeconds * xScale,
                               imageHeight - (previousValue * yScale),
                               (float)(data[i].Timestamp - statingTime).TotalSeconds * xScale,
                               imageHeight - (filteredDataValues[i] * yScale));
                }
                previousData  = data[i];
                previousValue = filteredDataValues[i];
            }
        }
Exemplo n.º 2
0
        public void DrawChart(ref List <InputTxtData> data,
                              ref Graphics g,
                              TimeSpan statingTime,
                              TimeSpan endingTime,
                              int MinValue,
                              int MaxValue,
                              int imageWidth,
                              int imageHeight)
        {
            List <int>   dataValues        = new List <int>();
            long         durationInSeconds = (long)(endingTime.TotalSeconds - statingTime.TotalSeconds);
            float        yScale            = (float)imageHeight / (float)MaxValue;
            float        xScale            = (float)imageWidth / (float)durationInSeconds;
            InputTxtData previousData      = null;
            int          previousValue     = MinValue;

            int   averageGroupSize    = data.Count / imageWidth;
            int   averageCounterIndex = 0;
            float averageValue        = 0;


            for (int i = 0; i < data.Count; i++)
            {
                int currentValue = (int)data[i].AirQualityValue;
                if (averageCounterIndex < averageGroupSize)
                {
                    averageValue += currentValue;
                    averageCounterIndex++;
                    continue;
                }
                else
                {
                    averageValue       /= averageGroupSize;
                    averageCounterIndex = 0;
                    currentValue        = (int)Math.Round(averageValue, MidpointRounding.AwayFromZero);
                }


                if (previousData != null)
                {
                    _currentPen = GetPen(currentValue);
                    Brush currentBrush = new SolidBrush(_currentPen.Color);
                    float x1           = (float)(previousData.Timestamp - statingTime).TotalSeconds * xScale;
                    float x2           = (float)(data[i].Timestamp - statingTime).TotalSeconds * xScale;
                    float width        = x2 - x1;
                    float height       = imageHeight - (currentValue * yScale);
                    g.DrawRectangle(_currentPen,
                                    x1,
                                    0,
                                    width,
                                    imageHeight);// - height);
                }
                previousData  = data[i];
                previousValue = currentValue;
            }
        }