public ResultsForm() { InitializeComponent(); newsFastGrid.Columns.Add(new FastColumn("MatchCriteria", "Критерий") { ColumnWidth = 55, ImageList = imageListGrid, IsHyperlinkStyleColumn = true, HyperlinkActiveCursor = Cursors.Hand }); newsFastGrid.Columns.Add(new FastColumn("CountryCode", "Страна")); newsFastGrid.Columns.Add(new FastColumn("Title", "Наименование")); newsFastGrid.Columns.Add(new FastColumn("FollowCount", "Следование")); newsFastGrid.Columns.Add(new FastColumn("Count", "Наблюдений")); newsFastGrid.Columns.Add(new FastColumn("Average", "Среднее") /*{ FormatString = "f7", colorColumnFormatter = delegate(object c, out Color? bc, out Color? fc) { fc = ((double) c >= 0) ? Color.DarkBlue : Color.DarkRed; bc = null; } }*/); indexFastChart.Axes.Add(new FastAxis(FastAxisDirection.X, false) /*{ ColorMainGrid = Color.DarkGray, LineColor = Color.Black, MinPixelsPerPoint = 55, DrawMainGrid = true, DrawSubGrid = true, ColorSubGrid = Color.Silver }*/); indexFastChart.Axes.Add(new FastAxis(FastAxisDirection.Y, false) /*{ AlwaysShowNil = true, ColorMainGrid = Color.DarkGray, LineColor = Color.Black, MinPixelsPerPoint = 25, DrawMainGrid = true, AutoScale100 = false }*/); var series = new FastSeries("", FastSeriesType.Линия, indexFastChart.Axes[0], indexFastChart.Axes[1], false); indexFastChart.series.Add(series); }
private void fastChart1_DoubleClick(object sender, EventArgs e) { fastChart1.Axes.Add(new FastAxis(FastAxisDirection.X, true)); fastChart1.Axes.Add(new FastAxis(FastAxisDirection.Y, false)); fastChart1.Axes.Add(new FastAxis(FastAxisDirection.Y, false)); var series = new FastSeries("EURUSD", FastSeriesType.Линия, fastChart1.Axes[0], fastChart1.Axes[1], true) { PenLine = new Pen(Color.DarkGray) { Width = 2 }, AntiAlias = true }; var rnd = new Random(); var start = 1.2940; for (var date = DateTime.Now.AddHours(-500); date <= DateTime.Now; date = date.AddHours(1)) { start += (rnd.Next(121) - 60) / 10000.0; series.points.Add(new FastSeriesPoint(date, start)); } fastChart1.series.Add(series); series = new FastSeries("DJ100", FastSeriesType.Линия, fastChart1.Axes[0], fastChart1.Axes[2], true) { PenLine = new Pen(Color.DeepPink) { Width = 2 }, AntiAlias = true }; start = 1800.0; for (var date = DateTime.Now.AddHours(-500); date <= DateTime.Now; date = date.AddHours(1)) { start += (rnd.Next(121) - 60) / 15.0; series.points.Add(new FastSeriesPoint(date, start)); } fastChart1.series.Add(series); fastChart1.Invalidate(); }
private void RenderChart(StringBuilder sb, string title, int width, int height, List<List<FastSeriesPoint>> series, List<string> seriesNames) { var seriesColors = new [] {Color.DarkBlue, Color.DarkOliveGreen, Color.Firebrick}; var needYearsInFormat = stat.listEquity[stat.listEquity.Count - 1].time.Year != stat.listEquity[0].time.Year; var formatString = needYearsInFormat ? "dd.MM.yyyy" : "dd MMM"; var chart = new FastChart.Chart.FastChart { ShowLegend = series.Count > 1, LegendPlacement = FastChart.Chart.FastChart.ChartLegendPlacement.Справа, BorderStyle = BorderStyle.None, DrawMargin = false }; var axisX = new FastAxis(FastAxisDirection.X, true) { ColorMainGrid = Color.FromArgb(205, 205, 205), ColorSubGrid = Color.FromArgb(220, 220, 220), DrawMainGrid = true, DrawSubGrid = true, LabelFormat = formatString }; // границы оси Y var min = double.MaxValue; var max = double.MinValue; foreach (var ser in series) { foreach (var pt in ser) { if (min > pt.y) min = pt.y; if (max < pt.y) max = pt.y; } } min = GetLowerBound(min); var axisY = new FastAxis(FastAxisDirection.Y, false) { ColorMainGrid = Color.FromArgb(205, 205, 205), ColorSubGrid = Color.FromArgb(220, 220, 220), DrawMainGrid = true, DrawSubGrid = true, AutoScale100 = false, MinValue = new FastChart.Chart.Cortege2<double, DateTime>(min, default(DateTime)), MaxValue = new FastChart.Chart.Cortege2<double, DateTime>(max * 1.05, default(DateTime)) }; chart.Axes.Add(axisX); chart.Axes.Add(axisY); // добавить серии и точки for (var i = 0; i < series.Count; i++) { var ser = new FastSeries(seriesNames[i], FastSeriesType.Линия, axisX, axisY, false) { PenLine = new Pen(seriesColors[i], 2f), AntiAlias = true }; ser.points.AddRange(series[i]); chart.series.Add(ser); } chart.Width = width; chart.Height = height; // рендерить чарт в картинку var img = new Bitmap(width, height); chart.DrawToBitmap(img, new Rectangle(0, 0, width - 1, height - 1)); // включить картинку в HTML var str = BaseWebServer.MakeEmbeddedPictureString(img); var imgStr = string.Format( "<img src=\"{0}\" alt=\"Доходность по счету\" style=\"cursor:pointer\" /> ", str); sb.AppendLine("<br/>"); sb.AppendLine(imgStr); sb.AppendLine(string.Format(" <p style=\"font-weight:bold\">{0}</p>", title)); }
/// <summary> /// вернуть полный путь к файлу с картинкой доходности /// </summary> private string MakeProfitChart(string tempFolder, Size chartSize) { var chart = new FastChart.Chart.FastChart { ShowLegend = true, LegendPlacement = FastChart.Chart.FastChart.ChartLegendPlacement.Справа, BorderStyle = BorderStyle.None, DrawMargin = false }; var axisX = new FastAxis(FastAxisDirection.X, true) { ColorMainGrid = Color.FromArgb(205, 205, 205), ColorSubGrid = Color.FromArgb(220, 220, 220), DrawMainGrid = true, DrawSubGrid = true, Step = new FastChart.Chart.Cortege2<double, TimeSpan>(0, new TimeSpan(356, 0, 0, 0)), LabelFormat = "yyyy" }; var maxProfit = (double) profitDic.Max(p => p.equity); var axisY = new FastAxis(FastAxisDirection.Y, false) { ColorMainGrid = Color.FromArgb(205, 205, 205), ColorSubGrid = Color.FromArgb(220, 220, 220), DrawMainGrid = true, DrawSubGrid = true, AutoScale100 = false, MinValue = new FastChart.Chart.Cortege2<double, DateTime>(0, default(DateTime)), MaxValue = new FastChart.Chart.Cortege2<double, DateTime>(maxProfit * 1.1, default(DateTime)) }; if (maxProfit > 1000) { var stepSize = maxProfit < 2000 ? 200 : maxProfit < 4000 ? 500 : 1000; axisY.Step = new FastChart.Chart.Cortege2<double, TimeSpan>(stepSize, default(TimeSpan)); } chart.Axes.Add(axisX); chart.Axes.Add(axisY); var seriesFund = new FastSeries("УК", FastSeriesType.Линия, axisX, axisY, false) {PenLine = new Pen(Color.FromArgb(80, 5, 5), 2f), AntiAlias = true }; seriesFund.points.AddRange(profitDic.Select(p => new FastSeriesPoint(p.time, p.equity)).ToList()); chart.series.Add(seriesFund); // серии бенчмарков var seriesBmA = new FastSeries(benchmarkA, FastSeriesType.Линия, axisX, axisY, false) { PenLine = new Pen(Color.FromArgb(5, 80, 5), 2f), AntiAlias = true }; var seriesBmB = new FastSeries(benchmarkB, FastSeriesType.Линия, axisX, axisY, false) { PenLine = new Pen(Color.FromArgb(5, 5, 80), 2f), AntiAlias = true }; seriesBmA.points.AddRange(MakeBenchmarkProfit1000Points(vamiBenchmarkA)); seriesBmB.points.AddRange(MakeBenchmarkProfit1000Points(vamiBenchmarkB)); chart.series.Add(seriesBmA); chart.series.Add(seriesBmB); chart.Width = chartSize.Width; chart.Height = chartSize.Height; var img = new Bitmap(chartSize.Width, chartSize.Height); chart.DrawToBitmap(img, new Rectangle(0, 0, chartSize.Width, chartSize.Height)); var path = string.Format("{0}\\chartProfit1000_{1}.png", tempFolder, DateTime.Now.Millisecond); img.Save(path, ImageFormat.Png); return path; }