Пример #1
0
        public static void SaveEquityCurve(
            SymbolInformation symbol,
            EvaluationResult result,
            string folderName)
        {
            var pane = new GraphPane();

            pane.Title.Text           = $"Equity Curve";
            pane.Title.FontSpec.Size  = 8;
            pane.Chart.Fill.IsScaled  = false;
            pane.Chart.Fill.Brush     = new SolidBrush(Color.DimGray);
            pane.Fill.Brush           = new SolidBrush(Color.DimGray);
            pane.Legend.Fill.Brush    = new SolidBrush(Color.DimGray);
            pane.Legend.FontSpec.Size = 6;

            var curve = pane.AddCurve("% Gain", new double[] { }, new double[] { }, LineColors[0], SymbolType.None);

            curve.Line.Width       = 2;
            curve.Line.IsVisible   = true;
            curve.Line.IsAntiAlias = true;

            foreach (var(day, equity) in result.EquityCurve)
            {
                curve.AddPoint(new XDate(day), equity);
            }

            pane.XAxis.Type = AxisType.Date;
            pane.XAxis.Scale.FontSpec.Size = 6;
            pane.XAxis.MinorGrid.IsVisible = true;
            pane.XAxis.MajorGrid.IsVisible = true;

            pane.YAxis.Scale.FontSpec.Size = 6;
            pane.YAxis.MinorGrid.IsVisible = true;
            pane.YAxis.MajorGrid.IsVisible = true;

            // force an axischange to plot all data and recalculate all axis
            // this is normally done by the control, but this is not possible in mvc3
            var bm = new Bitmap(1, 1);

            using (var g = Graphics.FromImage(bm))
            {
                pane.ReSize(g, new RectangleF(0, 0, 1280 * 5, 960 * 5));
                pane.AxisChange(g);
            }

            // create a stream to store a PNG-format image
            var actualFolder = Path.Combine(folderName, symbol.ISIN);

            Directory.CreateDirectory(actualFolder);
            var image = pane.GetImage(true);

            image.Save(
                Path.Combine(
                    actualFolder,
                    $"EquityCurve.png"),
                ImageFormat.Png);
        }
Пример #2
0
 /// <summary>
 /// Render content to a bitmap.
 /// </summary>
 protected override void Render(Bitmap bitmap, Rectangle renderRect)
 {
     using (var graphics = Graphics.FromImage(bitmap))
     {
         graphics.SetClip(renderRect);
         _graphPane.ReSize(graphics, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
         _graphPane.Draw(graphics);
     }
 }
Пример #3
0
        public static string SaveDataToPng(double[] data, int id)
        {
            ZedGraphControl zedGraphControl1 = new ZedGraphControl();
            GraphPane       paneA            = new GraphPane();
            PointPairList   listA            = new PointPairList();

            paneA.Title.IsVisible = false;
            paneA.XAxis.IsVisible = false;
            paneA.YAxis.IsVisible = false;
            if (id != 0)
            {
                paneA.XAxis.Scale.Max = 300000;
            }
            else
            {
                paneA.XAxis.Scale.Max = 550000;
            }

            for (int i = 0; i < data.Length; i++)
            {
                listA.Add(i, data[i]);
            }
            LineItem myCurveA = paneA.AddCurve("", listA, Color.Blue, SymbolType.None);

            using (Graphics g = zedGraphControl1.CreateGraphics())
            {
                paneA.AxisChange(g);
                paneA.ReSize(g, new RectangleF(0, 0, 1800, 300));
            }

            string url      = @"D:\\PipeWeb\\AdImages\\";
            string filename = DateTime.Now.ToString("yyyy-MM-dd") + "--" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + "--" + id.ToString();//以日期时间命名,避免文件名重复
            string strName  = url + filename + ".png";

            if (!Directory.Exists(url))         //如果不存在就创建file文件夹                 
            {
                Directory.CreateDirectory(url); //创建该文件夹 
                paneA.GetImage().Save(strName, ImageFormat.Png);
            }
            else
            {
                paneA.GetImage().Save(strName, ImageFormat.Png);
            }
            zedGraphControl1.Dispose();

            return(strName);
        }