Beispiel #1
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            int chartHeight = info.ChartHeight;
            int chartWidth = info.ChartWidth;

            int x = 0;
            int y = 0;

            HundredPctMicroChartStyle style = this.Style;
            int drawStep = Math.Max(style.MinBarSize, (chartWidth / (Math.Max(1, info.DataPoints.Count - 1))));
            int dataStep = Math.Max(1, ((info.DataPoints.Count * drawStep) / chartWidth));

            Graphics graphics = info.Graphics;
            double sum = info.Sum;

            if (dataStep > 1)
            {
                sum = 0;
                for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                    sum += Math.Abs(info.DataPoints[i]);
            }

            int colorsCount = style.BarColors.Count;
            int sliceColor = 0;

            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            int hotPointIndex = 0;
            
            using (Pen pen = new Pen(style.BarOutlineColor, 1))
            {
                for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                {
                    double value = Math.Abs(info.DataPoints[i]);

                    Rectangle barBounds = new Rectangle(x, y, (int)Math.Round(chartWidth * value / sum), chartHeight);

                    using (SolidBrush brush = new SolidBrush(style.BarColors[sliceColor]))
                        graphics.FillRectangle(brush, barBounds);
                    graphics.DrawRectangle(pen, barBounds);

                    microHotPoints[hotPointIndex] = new MicroChartHotPoint(GetHotPointBounds(barBounds), barBounds, style.BarColors[sliceColor], value, i);

                    hotPointIndex++;
                    
                    x += barBounds.Width;

                    sliceColor++;
                    if (sliceColor >= colorsCount)
                        sliceColor = 0;
                }
                
            }

            info.MicroChartHotPoints = microHotPoints;
        }
Beispiel #2
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            int chartWidth = Math.Min(info.ChartHeight, info.ChartWidth) - 1;
            int x = (info.ChartWidth - chartWidth) / 2;
            int y = (info.ChartHeight - chartWidth) / 2;

            int dataStep = Math.Max(1, ((info.DataPoints.Count * 15) / 360));

            PieMicroChartStyle style = this.Style;
            Graphics graphics = info.Graphics;
            double sum = info.Sum;

            if (dataStep > 1)
            {
                sum = 0;
                for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                    sum += Math.Abs(info.DataPoints[i]);
            }

            float angle = 0;
            
            int colorsCount = _Style.SliceColors.Count;
            int sliceColor = 0;
            
            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            int hotPointIndex = 0;

            using (Pen pen = new Pen(_Style.SliceOutlineColor, 1))
            {
                for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                {
                    double value = Math.Abs(info.DataPoints[i]);
                    float sweepAngle = (float)Math.Max(1, Math.Round((float)(360 * (value / sum))));

                    using (SolidBrush brush = new SolidBrush(_Style.SliceColors[sliceColor]))
                        graphics.FillPie(brush, x, y, chartWidth, chartWidth, angle, sweepAngle);
                    graphics.DrawPie(pen, x, y, chartWidth, chartWidth, angle, sweepAngle);

                    Rectangle hotPointBounds = new Rectangle(
                        x + (int)(chartWidth / 2 + chartWidth / 3 * Math.Cos((angle + sweepAngle / 2) * Math.PI / 180)),
                        y + (int)(chartWidth / 2 + chartWidth / 3 * Math.Sin((angle + sweepAngle / 2) * Math.PI / 180)),
                        1, 1);
                    hotPointBounds.Inflate(4, 4);
                    microHotPoints[hotPointIndex] = new MicroChartHotPoint(hotPointBounds, _Style.SliceColors[sliceColor], value, angle, sweepAngle, i);
                    hotPointIndex++;

                    angle += sweepAngle;
                    sliceColor++;
                    if (sliceColor >= colorsCount)
                        sliceColor = 0;
                }
            }

            info.MicroChartHotPoints = microHotPoints;
        }
Beispiel #3
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            Graphics graphics = info.Graphics;

            int chartHeight = info.ChartHeight - PointRadius * 2;
            int chartWidth = info.ChartWidth - PointRadius * 2;

            int drawStep = (int)Math.Max(2, chartWidth / (Math.Max(1, info.DataPoints.Count - 1)));
            int dataStep = Math.Max(1, ((info.DataPoints.Count * drawStep) / chartWidth));
            if (info.DataPoints.Count <= 2) dataStep = 1;
            int x = PointRadius;
            double dataPointMinValue = info.DataPointMinValue;
            double dataPointMaxValue = info.DataPointMaxValue;

            if (_MicroChartStyle.DrawZeroLine && dataPointMinValue > _MicroChartStyle.ZeroLineValue)
                dataPointMinValue = _MicroChartStyle.ZeroLineValue;
            if (_MicroChartStyle.DrawControlLine1)
            {
                if (dataPointMinValue > _MicroChartStyle.ControlLine1StartValue)
                    dataPointMinValue = _MicroChartStyle.ControlLine1StartValue;
                if (dataPointMinValue > _MicroChartStyle.ControlLine1EndValue)
                    dataPointMinValue = _MicroChartStyle.ControlLine1EndValue;
                if (dataPointMaxValue < _MicroChartStyle.ControlLine1StartValue)
                    dataPointMaxValue = _MicroChartStyle.ControlLine1StartValue;
                if (dataPointMaxValue < _MicroChartStyle.ControlLine1EndValue)
                    dataPointMaxValue = _MicroChartStyle.ControlLine1EndValue;
            }
            if (_MicroChartStyle.DrawControlLine2)
            {
                if (dataPointMinValue > _MicroChartStyle.ControlLine2StartValue)
                    dataPointMinValue = _MicroChartStyle.ControlLine2StartValue;
                if (dataPointMinValue > _MicroChartStyle.ControlLine2EndValue)
                    dataPointMinValue = _MicroChartStyle.ControlLine2EndValue;
                if (dataPointMaxValue < _MicroChartStyle.ControlLine2StartValue)
                    dataPointMaxValue = _MicroChartStyle.ControlLine2StartValue;
                if (dataPointMaxValue < _MicroChartStyle.ControlLine2EndValue)
                    dataPointMaxValue = _MicroChartStyle.ControlLine2EndValue;
            }

            
            double range = dataPointMaxValue - dataPointMinValue;
            if (range == 0) range = 1;

            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            Point[] chartPoints = new Point[totalPoints];
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            Point lowPoint = Point.Empty, highPoint = Point.Empty;
            int index = 0;
            for (int i = 0; i < info.DataPoints.Count; i += dataStep)
            {
                double value = info.DataPoints[i];
                Point p = new Point(x, (int)Math.Min((int)(chartHeight * (1 - (value - dataPointMinValue) / range)), chartHeight - 1) + PointRadius);
                if (lowPoint.IsEmpty && value == info.DataPointMinValue)
                    lowPoint = p;
                else if (/*highPoint.IsEmpty &&*/ value == dataPointMaxValue)
                    highPoint = p;

                chartPoints[index] = p;
                microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(p, info), new Rectangle(p.X - drawStep / 2, 0, drawStep, chartHeight), _MicroChartStyle.LineColor, value, index);
                index++;
                x += drawStep;
                if (x > chartWidth || i >= info.DataPoints.Count - dataStep * 2) x = chartWidth;
            }

            if (_MicroChartStyle.DrawAverageLine && !_MicroChartStyle.AverageLineColor.IsEmpty)
            {
                using (Pen pen = new Pen(_MicroChartStyle.AverageLineColor))
                    graphics.DrawLine(pen, 0, chartHeight / 2, chartWidth, chartHeight / 2);
            }

            //if (_MicroChartStyle.DrawTrendLine && !_MicroChartStyle.TrendLineColor.IsEmpty)
            //{
            //    using (Pen pen = new Pen(_MicroChartStyle.TrendLineColor))
            //        graphics.DrawLine(pen, 0, (int)(chartHeight * (1 - (info.TrendInfo.Start - dataPointMinValue) / range)),
            //            chartWidth, (int)(chartHeight * (1 - (info.TrendInfo.End - dataPointMinValue) / range)));
            //}

            if (_MicroChartStyle.DrawZeroLine && !_MicroChartStyle.ZeroLineColor.IsEmpty)
            {
                using (Pen pen = new Pen(_MicroChartStyle.ZeroLineColor))
                {
                    int y = Math.Min((int)(chartHeight * (1 - (_MicroChartStyle.ZeroLineValue - dataPointMinValue) / range)) + PointRadius, (chartHeight + PointRadius) - 1);
                    if (y < 0) y = 0;
                    graphics.DrawLine(pen, 0, y, chartWidth, y);
                }
            }

            if (_MicroChartStyle.DrawControlLine1 && !_MicroChartStyle.ControlLine1Color.IsEmpty)
            {
                using (Pen pen = new Pen(_MicroChartStyle.ControlLine1Color))
                {
                    int y1 = Math.Min((int)(chartHeight * (1 - (_MicroChartStyle.ControlLine1StartValue - dataPointMinValue) / range)) + PointRadius, (chartHeight + PointRadius) - 1);
                    if (y1 < 0) y1 = 0;
                    int y2 = Math.Min((int)(chartHeight * (1 - (_MicroChartStyle.ControlLine1EndValue - dataPointMinValue) / range)) + PointRadius, (chartHeight + PointRadius) - 1);
                    if (y2 < 0) y2 = 0;
                    graphics.DrawLine(pen, 0, y1, chartWidth, y2);
                }
            }
            if (_MicroChartStyle.DrawControlLine2 && !_MicroChartStyle.ControlLine2Color.IsEmpty)
            {
                using (Pen pen = new Pen(_MicroChartStyle.ControlLine2Color))
                {
                    int y1 = Math.Min((int)(chartHeight * (1 - (_MicroChartStyle.ControlLine2StartValue - dataPointMinValue) / range)) + PointRadius, (chartHeight + PointRadius) - 1);
                    if (y1 < 0) y1 = 0;
                    int y2 = Math.Min((int)(chartHeight * (1 - (_MicroChartStyle.ControlLine2EndValue - dataPointMinValue) / range)) + PointRadius, (chartHeight + PointRadius) - 1);
                    if (y2 < 0) y2 = 0;
                    graphics.DrawLine(pen, 0, y1, chartWidth, y2);
                }
            }

            if (chartPoints.Length > 1)
            {
                using (Pen pen = new Pen(_MicroChartStyle.LineColor))
                    graphics.DrawLines(pen, chartPoints);
            }

            if (!lowPoint.IsEmpty && !_MicroChartStyle.LowPointColor.IsEmpty && chartPoints.Length > 0)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.LowPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(lowPoint));
            }

            if (!highPoint.IsEmpty && !_MicroChartStyle.HighPointColor.IsEmpty && chartPoints.Length > 0)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.HighPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(highPoint));
            }

            if (!_MicroChartStyle.FirstPointColor.IsEmpty && chartPoints.Length > 0)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.FirstPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(chartPoints[0]));
            }

            if (!_MicroChartStyle.LastPointColor.IsEmpty && chartPoints.Length > 1)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.LastPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(chartPoints[chartPoints.Length - 1]));
            }

            info.MicroChartHotPoints = microHotPoints;

        }
Beispiel #4
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            Graphics graphics = info.Graphics;

            int chartHeight = info.ChartHeight;
            int chartWidth = info.ChartWidth;

            BarMicroChartStyle style = this.Style;
            int drawStep = Math.Max(style.MinBarSize, (chartHeight / (Math.Max(1, info.DataPoints.Count))));
            int dataStep = Math.Max(1, ((info.DataPoints.Count * (drawStep + 1)) / chartHeight));
            int y = 0;
            double dataPointMinValue = info.DataPointMinValue;

            if (dataPointMinValue > style.ZeroLineValue)
                dataPointMinValue = style.ZeroLineValue;

            double range = info.DataPointMaxValue - dataPointMinValue;
            if (range == 0) range = 1;

            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            int index = 0;
            int zeroX = Math.Min((int)(chartWidth * (1 - (style.ZeroLineValue - dataPointMinValue) / range)), chartWidth);

            System.Drawing.Drawing2D.SmoothingMode smoothingMode = graphics.SmoothingMode;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
            using (SolidBrush positiveBarBrush = new SolidBrush(style.PositiveBarColor))
            {
                using (SolidBrush negativeBarBrush = new SolidBrush(style.NegativeBarColor))
                {
                    for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                    {
                        double value = info.DataPoints[i];
                        int x = Math.Min((int)(chartWidth * (1 - (value - dataPointMinValue) / range)), chartWidth - 1);
                        Rectangle barBounds = Rectangle.Empty;
                        if (value > style.ZeroLineValue)
                        {
                            if (zeroX == chartWidth && x == zeroX) x--;
                            barBounds = new Rectangle(x, y, Math.Max(1, zeroX - x), drawStep);

                            if (value == info.DataPointMaxValue && !style.HighPointBarColor.IsEmpty)
                            {
                                using (SolidBrush brush = new SolidBrush(style.HighPointBarColor))
                                    graphics.FillRectangle(brush, barBounds);
                            }
                            else
                                graphics.FillRectangle(positiveBarBrush, barBounds);

                            microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(barBounds, true), new Rectangle(0, barBounds.Y, chartWidth, barBounds.Height), style.PositiveBarColor, value, index);
                        }
                        else
                        {
                            barBounds = new Rectangle(zeroX, y, Math.Max(1, x - zeroX), drawStep);
                            
                            if (value == info.DataPointMinValue && !style.LowPointBarColor.IsEmpty)
                            {
                                using (SolidBrush brush = new SolidBrush(style.LowPointBarColor))
                                    graphics.FillRectangle(brush, barBounds);
                            }
                            else
                                graphics.FillRectangle(negativeBarBrush, barBounds);

                            microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(barBounds, false), new Rectangle(0, barBounds.Y, chartWidth, barBounds.Height), style.NegativeBarColor, value, index);
                        }

                        index++;
                        y += drawStep + 1;
                    }
                }
            }
            graphics.SmoothingMode = smoothingMode;
            info.MicroChartHotPoints = microHotPoints;
        }
Beispiel #5
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            Graphics graphics = info.Graphics;

            int chartHeight = info.ChartHeight;
            int chartWidth = info.ChartWidth;

            BarMicroChartStyle style = this.Style;
            int drawStep = Math.Max(style.MinBarSize, (chartWidth / (Math.Max(1, info.DataPoints.Count - 1))));
            int dataStep = Math.Max(1, ((info.DataPoints.Count * drawStep) / chartWidth));
            int x = 0;

            double zeroValue = style.ZeroLineValue;

            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            int index = 0;
            int zeroY = chartHeight / 2;

            System.Drawing.Drawing2D.SmoothingMode smoothingMode = graphics.SmoothingMode;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

            using (SolidBrush positiveBarBrush = new SolidBrush(style.PositiveBarColor))
            {
                using (SolidBrush negativeBarBrush = new SolidBrush(style.NegativeBarColor))
                {
                    for (int i = 0; i < info.DataPoints.Count; i += dataStep)
                    {
                        double value = info.DataPoints[i];
                        if (value > style.ZeroLineValue)
                        {
                            Rectangle barBounds = new Rectangle(x, 0, drawStep, Math.Max(1, zeroY));
                            
                            if (value == info.DataPointMaxValue && !style.HighPointBarColor.IsEmpty)
                            {
                                using (SolidBrush brush = new SolidBrush(style.HighPointBarColor))
                                    graphics.FillRectangle(brush, barBounds);
                            }
                            else
                                graphics.FillRectangle(positiveBarBrush, barBounds);

                            microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(barBounds, true), new Rectangle(barBounds.X, 0, barBounds.Width, chartHeight), style.PositiveBarColor, value, index);
                        }
                        else
                        {
                            Rectangle barBounds = new Rectangle(x, zeroY, drawStep, Math.Max(1, chartHeight - zeroY));

                            if (value == info.DataPointMinValue && !style.LowPointBarColor.IsEmpty)
                            {
                                using (SolidBrush brush = new SolidBrush(style.LowPointBarColor))
                                    graphics.FillRectangle(brush, barBounds);
                            }
                            else
                                graphics.FillRectangle(negativeBarBrush, barBounds);

                            microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(barBounds, false), new Rectangle(barBounds.X, 0, barBounds.Width, chartHeight), style.NegativeBarColor, value, index);
                        }

                        index++;
                        x += drawStep;
                    }
                }
            }
            graphics.SmoothingMode = smoothingMode;
            info.MicroChartHotPoints = microHotPoints;
        }
Beispiel #6
0
        public override void CreateChart(MicroChartRenderInfo info)
        {
            Graphics graphics = info.Graphics;

            int chartHeight = info.ChartHeight - PointRadius * 2;
            int chartWidth = info.ChartWidth - PointRadius * 2;

            int drawStep = Math.Max(3, (chartWidth / (Math.Max(1, info.DataPoints.Count - 1))));
            int dataStep = Math.Max(1, ((info.DataPoints.Count * drawStep) / chartWidth));
            int x = PointRadius;
            double dataPointMinValue = info.DataPointMinValue;

            double zeroValue = _MicroChartStyle.ZeroLineValue;
            if (dataPointMinValue > zeroValue)
                dataPointMinValue = zeroValue;

            double range = info.DataPointMaxValue - dataPointMinValue;
            if (range == 0) range = 1;
            int zeroY = Math.Min((int)(chartHeight * (1 - (zeroValue - dataPointMinValue) / range)), chartHeight - 1) + PointRadius;

            int totalPoints = (int)Math.Ceiling((double)info.DataPoints.Count / dataStep);
            Point[] chartPoints = new Point[totalPoints];
            MicroChartHotPoint[] microHotPoints = new MicroChartHotPoint[totalPoints];
            int index = 0;
            GraphicsPath areaPath = new GraphicsPath();
            Point lastPoint = new Point(0, zeroY);
            Point lowPoint = Point.Empty, highPoint = Point.Empty;

            for (int i = 0; i < info.DataPoints.Count; i += dataStep)
            {
                double value = info.DataPoints[i];
                double nextValue = (i < (info.DataPoints.Count - 1)) ? info.DataPoints[i + 1] : zeroValue;
                Point p = new Point(x, Math.Min((int)(chartHeight * (1 - (value - dataPointMinValue) / range)), chartHeight - 1) + PointRadius);
                Point endPoint = new Point(x + drawStep, Math.Min((int)(chartHeight * (1 - (nextValue - dataPointMinValue) / range)), chartHeight - 1));

                if (lowPoint.IsEmpty && value == info.DataPointMinValue)
                    lowPoint = p;
                else if (/*highPoint.IsEmpty &&*/ value == info.DataPointMaxValue)
                    highPoint = p;

                chartPoints[index] = p;

                if (i + dataStep >= info.DataPoints.Count)
                    areaPath.AddPolygon(new Point[] { new Point(x, zeroY), p, endPoint, new Point(chartWidth, endPoint.Y), new Point(chartWidth, zeroY) });
                else
                    areaPath.AddPolygon(new Point[] { new Point(x, zeroY), p, endPoint, new Point(endPoint.X, zeroY) });

                microHotPoints[index] = new MicroChartHotPoint(GetHotPointBounds(p, info), new Rectangle(p.X - drawStep / 2, 0, endPoint.X - p.X, chartHeight), Color.Gray /*_MicroChartStyle.LineColor*/, value, index);
                index++;
                x += drawStep;
            }

            using (SolidBrush brush = new SolidBrush(_MicroChartStyle.AreaColor))
                graphics.FillPath(brush, areaPath);
            areaPath.Dispose();

            if (!lowPoint.IsEmpty && !_MicroChartStyle.LowPointColor.IsEmpty)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.LowPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(lowPoint));
            }

            if (!highPoint.IsEmpty && !_MicroChartStyle.HighPointColor.IsEmpty)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.HighPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(highPoint));
            }

            if (!_MicroChartStyle.FirstPointColor.IsEmpty && chartPoints.Length > 0)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.FirstPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(chartPoints[0]));
            }

            if (!_MicroChartStyle.LastPointColor.IsEmpty && chartPoints.Length > 1)
            {
                using (SolidBrush brush = new SolidBrush(_MicroChartStyle.LastPointColor))
                    graphics.FillPolygon(brush, GetChartPointBounds(chartPoints[chartPoints.Length - 1]));
            }

            info.MicroChartHotPoints = microHotPoints;

        }