Beispiel #1
0
            public override void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
            {
                NGraphics graphics = eventArgs.Graphics;

                double     dPreviousValue, dCurrentValue;
                int        nBarCount = 10;
                NChart     chart     = panel as NChart;
                NBarSeries bar       = (NBarSeries)chart.Series[0];

                NAxis horzAxis = chart.Axis(StandardAxis.PrimaryX);
                NAxis vertAxis = chart.Axis(StandardAxis.PrimaryY);

                NVector3DF vecClientPoint = new NVector3DF();
                NVector3DF vecModelPoint  = new NVector3DF();

                int nBarSize = (int)(chart.ContentArea.Width * (int)bar.WidthPercent) / (nBarCount * 200);

                // init pens and brushes
                NStrokeStyle rectStrokeStyle = new NStrokeStyle(1, Color.DarkBlue);
                NFillStyle   rectFillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(125, Color.LightBlue), Color.FromArgb(125, Color.DarkBlue));

                NLightingImageFilter lightingFilter = new NLightingImageFilter();

                NStrokeStyle positiveArrowStrokeStyle = new NStrokeStyle(1, Color.DarkGreen);
                NFillStyle   positiveArrowFillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Green, Color.DarkGreen);

                positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter);

                NStrokeStyle equalSignStrokeStyle = new NStrokeStyle(1, Color.DarkGray);
                NFillStyle   equalSignFillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Gray, Color.DarkGray);

                positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter);

                NStrokeStyle negativeArrowStrokeStyle = new NStrokeStyle(1, Color.DarkRed);
                NFillStyle   negativeArrowFillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Red, Color.DarkRed);

                positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter);

                for (int i = 1; i < bar.Values.Count; i++)
                {
                    dPreviousValue = (double)bar.Values[i - 1];
                    dCurrentValue  = (double)bar.Values[i];

                    vecModelPoint.X = horzAxis.TransformScaleToModel(false, i);
                    vecModelPoint.Y = vertAxis.TransformScaleToModel(false, (float)(double)bar.Values[i]);
                    vecModelPoint.Z = 0;

                    if (!chart.TransformModelToClient(vecModelPoint, ref vecClientPoint))
                    {
                        continue;
                    }

                    RectangleF rcArrowRect = new RectangleF(vecClientPoint.X - nBarSize, vecClientPoint.Y - nBarSize, 2 * nBarSize, 2 * nBarSize);

                    if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0)
                    {
                        continue;
                    }

                    if (!DisplayMark(dCurrentValue, dPreviousValue))
                    {
                        continue;
                    }

                    // draw arrow background
                    GraphicsPath path = GetRoundRectanglePath(rcArrowRect);

                    graphics.PaintPath(rectFillStyle, rectStrokeStyle, path);

                    path.Dispose();

                    rcArrowRect.Inflate(-5, -5);

                    // draw the arrow itself
                    if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0)
                    {
                        continue;
                    }

                    if (dCurrentValue < dPreviousValue)
                    {
                        // draw negative arrow
                        path = GetArrowPath(rcArrowRect, false);

                        graphics.PaintPath(negativeArrowFillStyle, negativeArrowStrokeStyle, path);

                        path.Dispose();
                    }
                    else if (dCurrentValue > dPreviousValue)
                    {
                        // draw positive arrow
                        path = GetArrowPath(rcArrowRect, true);

                        graphics.PaintPath(positiveArrowFillStyle, positiveArrowStrokeStyle, path);

                        path.Dispose();
                    }
                    else
                    {
                        // draw equal sign
                        NRectangleF rect = new NRectangleF(rcArrowRect.Left, rcArrowRect.Top, rcArrowRect.Width, rcArrowRect.Height / 3.0f);

                        graphics.PaintRectangle(equalSignFillStyle, equalSignStrokeStyle, rect);

                        rect = new NRectangleF(rcArrowRect.Left, rcArrowRect.Bottom - rect.Height, rcArrowRect.Width, rect.Height);

                        graphics.PaintRectangle(equalSignFillStyle, equalSignStrokeStyle, rect);
                    }
                }
            }
Beispiel #2
0
            public override void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
            {
                Graphics graphics = eventArgs.Graphics.DeviceGraphics;

                double     dPreviousValue, dCurrentValue;
                int        nBarCount = 10;
                NChart     chart     = panel as NChart;
                NBarSeries bar       = (NBarSeries)chart.Series[0];

                NAxis horzAxis = chart.Axis(StandardAxis.PrimaryX);
                NAxis vertAxis = chart.Axis(StandardAxis.PrimaryY);

                NVector3DF vecClientPoint = new NVector3DF();
                NVector3DF vecModelPoint  = new NVector3DF();

                int nBarSize = (int)(chart.ContentArea.Width * (int)bar.WidthPercent) / (nBarCount * 200);

                // init pens and brushes
                Pen        penRectBorder = new Pen(Color.DarkBlue);
                SolidBrush brushRectFill = new SolidBrush(Color.FromArgb(125, Color.LightBlue));

                Pen        penPositiveArrowBorder = new Pen(Color.DarkGreen);
                SolidBrush brushPositiveArrowFill = new SolidBrush(Color.Green);

                Pen        penEqualSignBorder = new Pen(Color.DarkGray);
                SolidBrush brushEqualSignFill = new SolidBrush(Color.Gray);

                Pen        penNegativeArrowBorder = new Pen(Color.DarkRed);
                SolidBrush brushNegativeArrowFill = new SolidBrush(Color.Red);

                for (int i = 1; i < bar.Values.Count; i++)
                {
                    dPreviousValue = (double)bar.Values[i - 1];
                    dCurrentValue  = (double)bar.Values[i];

                    vecModelPoint.X = horzAxis.TransformScaleToModel(false, i);
                    vecModelPoint.Y = vertAxis.TransformScaleToModel(false, (float)(double)bar.Values[i]);
                    vecModelPoint.Z = 0;

                    if (!chart.TransformModelToClient(vecModelPoint, ref vecClientPoint))
                    {
                        continue;
                    }

                    RectangleF rcArrowRect = new RectangleF(vecClientPoint.X - nBarSize, vecClientPoint.Y - nBarSize, 2 * nBarSize, 2 * nBarSize);

                    if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0)
                    {
                        continue;
                    }

                    if (!DisplayMark(dCurrentValue, dPreviousValue))
                    {
                        continue;
                    }

                    // draw arrow background
                    GraphicsPath path = GetRoundRectanglePath(rcArrowRect);

                    graphics.FillPath(brushRectFill, path);
                    graphics.DrawPath(penRectBorder, path);

                    path.Dispose();

                    rcArrowRect.Inflate(-5, -5);

                    // draw the arrow itself
                    if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0)
                    {
                        continue;
                    }

                    if (dCurrentValue < dPreviousValue)
                    {
                        // draw negative arrow
                        path = GetArrowPath(rcArrowRect, false);

                        graphics.FillPath(brushNegativeArrowFill, path);
                        graphics.DrawPath(penNegativeArrowBorder, path);

                        path.Dispose();
                    }
                    else if (dCurrentValue > dPreviousValue)
                    {
                        // draw positive arrow
                        path = GetArrowPath(rcArrowRect, true);

                        graphics.FillPath(brushPositiveArrowFill, path);
                        graphics.DrawPath(penPositiveArrowBorder, path);

                        path.Dispose();
                    }
                    else
                    {
                        // draw equal sign
                        RectangleF rect = new RectangleF(rcArrowRect.Left, rcArrowRect.Top, rcArrowRect.Width, rcArrowRect.Height / 3.0f);

                        graphics.FillRectangle(brushEqualSignFill, rect.Left, rect.Top, rect.Width, rect.Height);
                        graphics.DrawRectangle(penEqualSignBorder, rect.Left, rect.Top, rect.Width, rect.Height);

                        rect = new RectangleF(rcArrowRect.Left, rcArrowRect.Bottom - rect.Height, rcArrowRect.Width, rect.Height);

                        graphics.FillRectangle(brushEqualSignFill, rect.Left, rect.Top, rect.Width, rect.Height);
                        graphics.DrawRectangle(penEqualSignBorder, rect.Left, rect.Top, rect.Width, rect.Height);
                    }
                }

                // dispose pens and brushes
                penPositiveArrowBorder.Dispose();
                brushPositiveArrowFill.Dispose();

                penNegativeArrowBorder.Dispose();
                brushNegativeArrowFill.Dispose();

                brushRectFill.Dispose();
                penRectBorder.Dispose();
            }