Пример #1
0
        private static void PlotAxes(BoundsF bounds, double scale, Bitmap bmp)
        {
            double unitsX = UnitSize(bounds.Bounds.Width);
            double unitsY = UnitSize(bounds.Bounds.Height);

            using Graphics g = Graphics.FromImage(bmp);
            for (double v = RoundUp(bounds.Bounds.X, unitsX); v < bounds.Bounds.Right; v += unitsX)
            {
                List <PointF> rule = new List <PointF>
                {
                    new PointF {
                        X = (float)v, Y = bounds.Bounds.Y
                    },
                    new PointF {
                        X = (float)v, Y = bounds.Bounds.Bottom
                    }
                };
                PlotGraph(rule, g, bounds.Bounds, scale, Color.Gray);
                LabelXRule(v, g, bounds, scale);
            }
            for (double v = RoundUp(bounds.Bounds.Y, unitsY); v < bounds.Bounds.Bottom; v += unitsY)
            {
                List <PointF> rule = new List <PointF>
                {
                    new PointF {
                        Y = (float)v, X = bounds.Bounds.X
                    },
                    new PointF {
                        Y = (float)v, X = bounds.Bounds.Right
                    }
                };
                PlotGraph(rule, g, bounds.Bounds, scale, Color.Gray);
                LabelYRule(v, g, bounds, scale);
            }
        }
Пример #2
0
        public static Image PlotGraphs(IEnumerable <IEnumerable <PointF> > points, int width, int height, Color?color = null)
        {
            Color[] colours = { Color.Black, Color.Brown, Color.Red,    Color.DarkBlue,
                                Color.Green, Color.Blue,  Color.Purple, Color.Gray };
            if (color.HasValue)
            {
                colours = new Color[] { color.Value }
            }
            ;

            Bitmap  bmp    = new Bitmap(width, height);
            BoundsF bounds = new BoundsF();
            List <List <PointF> > plots = new List <List <PointF> >();

            foreach (IEnumerable <PointF> pl in points)
            {
                plots.Add(bounds.Track(pl).ToList());
            }
            double scale = ScaleFactor(bounds.Bounds, width, height);

            using Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(Brushes.White, 0, 0, width, height);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            PlotAxes(bounds, scale, bmp);
            int index = 0;

            foreach (List <PointF> pl in plots)
            {
                PlotGraph(pl, g, bounds.Bounds, scale, colours[index++ % colours.Length]);
            }
            return(bmp);
        }
Пример #3
0
        private static void LabelXRule(double v, Graphics g, BoundsF bounds, double scale)
        {
            // First generate label string

            string label   = v.ToString("G2");
            Font   font    = new Font("Consolas", 30F);
            SizeF  txtSize = g.MeasureString(label, font);

            // Find the line position

            float x = (float)(0.5 + scale * (v - bounds.Bounds.X));

            x -= txtSize.Width / 2;
            g.FillRectangle(Brushes.White, x, 0, txtSize.Width, txtSize.Height);
            g.DrawString(label, font, Brushes.Gray, x, 0);
        }