public static void AddPieChartToPDF() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Create a page. PdfPage page = document.AddPage(); // Generate a 2d pie chart graph Chart chart = PieChart(); // Create a chart frame, set chart location and size ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); chartFrame.Add(chart); // Render chart symbols into pdf page XGraphics g = XGraphics.FromPdfPage(page); chartFrame.Draw(g); // Save and show the document document.Save("PieChart.pdf"); Process.Start("PieChart.pdf"); }
public void CreateDiagram <T>(List <T> students, string path) { PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); var props = typeof(T).GetProperties().Where((x) => FieldType.Split(' ').Contains(x.Name)).ToList(); Dictionary <string, int> producers = new Dictionary <string, int>(); foreach (var p in students) { var prod = props[2].GetValue(p).ToString(); if (!producers.ContainsKey(prod)) { producers.Add(prod, 0); } producers[prod] += 1; } ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); chartFrame.Add(ColumnChart(producers)); XGraphics g = XGraphics.FromPdfPage(page); chartFrame.Draw(g); document.Save(path); }
public static void ChangePDFPieChartAndFrameColor() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Create a page. PdfPage page = document.AddPage(); // Generate a 2d pie chart graph Chart chart = new Chart(ChartType.Pie2D); // Add series data Series series = chart.SeriesCollection.AddSeries(); series.Add(new double[] { 5, 6, 3 }); // Add series legend XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Series 1", "Series 2", "Series 3"); chart.Legend.Docking = DockingType.Right; // Set fill color for series 1 series.Elements[0].FillFormat.Color = XColors.Red; // Set fill color for series 2 series.Elements[1].FillFormat.Color = XColors.Blue; // Set fill color for series 3 series.Elements[2].FillFormat.Color = XColors.Yellow; // Set label display type chart.DataLabel.Type = DataLabelType.Percent; // Set label location chart.DataLabel.Position = DataLabelPosition.Center; // Create a chart frame, set chart location and size ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); // Set background color for frame chartFrame.BackgroudFormat = XBrushes.White; // Set border color for frame chartFrame.BorderFormat = XPens.Black; chartFrame.Add(chart); // Render chart symbols into pdf page XGraphics g = XGraphics.FromPdfPage(page); chartFrame.Draw(g); // Save and show the document document.Save("PieColorChart.pdf"); Process.Start("PieColorChart.pdf"); }
private void tvNavigation_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { this.chartFrame = new ChartFrame(); this.chartFrame.Location = new XPoint(30, 30); this.chartFrame.Size = new XSize(500, 600); Chart chart = null; switch (e.Node.Text.ToLower()) { case "line chart": chart = ChartSamples.LineChart(); break; case "column chart": chart = ChartSamples.ColumnChart(); break; case "stacked column chart": chart = ChartSamples.ColumnStackedChart(); break; case "bar chart": chart = ChartSamples.BarChart(); break; case "stacked bar chart": chart = ChartSamples.BarStackedChart(); break; case "area chart": chart = ChartSamples.AreaChart(); break; case "pie chart": chart = ChartSamples.PieChart(); break; case "pie exploded chart": chart = ChartSamples.PieExplodedChart(); break; case "combination chart": chart = ChartSamples.CombinationChart(); break; } this.chartFrame.Add(chart); this.pagePreview.SetRenderEvent(new PagePreview.RenderEvent(chartFrame.Draw)); }
public ChartControl() { InitializeComponent(); visualSettings = new ChartVisualSettings(this); SetStyle((ControlStyles)0x22012, true); _chartFrame = new ChartFrame(); _panes = new PaneCollection(this); _interactivityTools = new InteractivityToolCollection(this); CreateStockSeries(); _window = new Window(this); candleRange = new CandleRange(StockSeries); Timeframe = new BarSettings(); Timeframe.Intervals.Add(60); //DoubleBuffered = true; }
private ChartFrame MapObject(DocumentObjectModel.Shapes.Charts.Chart domChart) { ChartFrame chartFrame = new ChartFrame(); chartFrame.Size = new XSize(domChart.Width.Point, domChart.Height.Point); chartFrame.Location = new XPoint(domChart.Left.Position.Point, domChart.Top.Position.Point); Chart chart = new Chart((ChartType)domChart.Type); if (!domChart.IsNull("XAxis")) { AxisMapper.Map(chart.XAxis, domChart.XAxis); } if (!domChart.IsNull("YAxis")) { AxisMapper.Map(chart.YAxis, domChart.YAxis); } PlotAreaMapper.Map(chart.PlotArea, domChart.PlotArea); SeriesCollectionMapper.Map(chart.SeriesCollection, domChart.SeriesCollection); LegendMapper.Map(chart, domChart); chart.DisplayBlanksAs = (BlankType)domChart.DisplayBlanksAs; chart.HasDataLabel = domChart.HasDataLabel; if (!domChart.IsNull("DataLabel")) { DataLabelMapper.Map(chart.DataLabel, domChart.DataLabel); } if (!domChart.IsNull("Style")) { FontMapper.Map(chart.Font, domChart.Document, domChart.Style); } if (!domChart.IsNull("Format.Font")) { FontMapper.Map(chart.Font, domChart.Format.Font); } if (!domChart.IsNull("XValues")) { XValuesMapper.Map(chart.XValues, domChart.XValues); } chartFrame.Add(chart); return(chartFrame); }
public static void ExportToPDF(ConsoleTable consoletable, string TypeOfDAta) { PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); Chart chart = LineChart(); ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); chartFrame.Add(chart); XGraphics g = XGraphics.FromPdfPage(page); chartFrame.Draw(g); document.Save("IndexResults.pdf"); // This is the code to open the PDF file that we just created. //Process.Start("IndexResults.pdf"); }
private void ShowDocument(object obj) { PdfDocument document = new PdfDocument(); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont titleFont = new XFont("Times New Roman", 28, XFontStyle.Bold, options); XFont regularFont = new XFont("Times New Roman", 18, XFontStyle.Regular, options); PdfPage page = document.AddPage(); page.Size = PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); gfx.DrawString(Constants.HEADER, titleFont, XBrushes.Black, new XRect(0, 50, page.Width, page.Height), XStringFormats.TopCenter); XTextFormatter authorTextFormatter = new XTextFormatter(gfx); authorTextFormatter.Alignment = XParagraphAlignment.Right; authorTextFormatter.DrawString(Constants.PROJECT_INFO, regularFont, XBrushes.Black, new XRect(-40, page.Height - 100, page.Width, page.Height), XStringFormats.TopLeft); XTextFormatter documentInfo = new XTextFormatter(gfx); authorTextFormatter.Alignment = XParagraphAlignment.Left; authorTextFormatter.DrawString( string.Format(Constants.DOCUMENT_INFO, SelectedType, SelectedCategory, SelectedPeriod), regularFont, XBrushes.Black, new XRect(40, 150, page.Width, page.Height), XStringFormats.TopLeft); ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(40, 200); chartFrame.Size = new XSize(500, 500); chartFrame.Add(LineChart()); chartFrame.Draw(gfx); const string filename = "Accounting.pdf"; document.Save(filename); Process.Start(filename); }
private async void GetWeatherByXML_Click(object sender, RoutedEventArgs e) { XmlDocument doc = await Services.WeatherService.GetXml(LocalTextBox.Text); StringBuilder str = new StringBuilder(); XmlElement root = doc.DocumentElement; if (root.GetElementsByTagName("error").Length == 0) { str.AppendFormat("城市:{0}\n", LocalTextBox.Text); str.AppendFormat("当前温度:{0}\n", GetTextFromXml(root, "wendu")); str.AppendFormat("当前湿度:{0}\n", GetTextFromXml(root, "shidu")); str.AppendFormat("空气质量:{0}\n", GetTextFromXml(root, "quality")); str.AppendFormat("PM25:{0}\n", GetTextFromXml(root, "pm25")); str.AppendFormat("建议:{0}\n", GetTextFromXml(root, "suggest")); XmlNodeList forecast = root.GetElementsByTagName("weather"); var source = new ObservableCollection <ListItem>(); for (int i = 0; i < forecast.Count; i++) { XmlElement day = (XmlElement)((XmlElement)forecast[i]).GetElementsByTagName("day")[0]; source.Add(new ListItem { date = ((XmlElement)forecast[i]).GetElementsByTagName("date")[0].InnerText, high = ((XmlElement)forecast[i]).GetElementsByTagName("high")[0].InnerText.Substring(3), low = ((XmlElement)forecast[i]).GetElementsByTagName("low")[0].InnerText.Substring(3), type = day.GetElementsByTagName("type")[0].InnerText, wind = day.GetElementsByTagName("fengxiang")[0].InnerText, }); } ListViewModel.Source = source; ChartFrame.Navigate(typeof(ListPage)); } else { str.AppendFormat("未找到城市:{0}\n", LocalTextBox.Text); } WeatherContent.Text = str.ToString(); }
private async void GetWeatherByJson_Click(object sender, RoutedEventArgs e) { JsonObject data = await Services.WeatherService.GetJson(LocalTextBox.Text); StringBuilder str = new StringBuilder(); if (data["message"].GetString().Equals("Success !")) { JsonObject info = data["data"].GetObject(); str.AppendFormat("城市:{0}\n", LocalTextBox.Text); str.AppendFormat("当前温度:{0}\n", info["wendu"].GetString()); str.AppendFormat("当前湿度:{0}\n", info["shidu"].GetString()); str.AppendFormat("空气质量:{0}\n", info["quality"].GetString()); str.AppendFormat("PM25:{0}\n", info["pm25"].GetNumber()); str.AppendFormat("建议:{0}\n", info["ganmao"].GetString()); JsonArray forecast = info["forecast"].GetArray(); var source = new ObservableCollection <ListItem>(); for (int i = 0; i < forecast.Count; i++) { JsonObject item = forecast[i].GetObject(); source.Add(new ListItem { date = item["date"].GetString(), high = item["high"].GetString().Substring(3).Replace(".0", ""), low = item["low"].GetString().Substring(3).Replace(".0", ""), type = item["type"].GetString(), wind = item["fx"].GetString(), }); } ListViewModel.Source = source; ChartFrame.Navigate(typeof(ListPage)); } else { str.AppendFormat("未找到城市:{0}\n", LocalTextBox.Text); } WeatherContent.Text = str.ToString(); }
private void DrawChart(XGraphics g, PdfPage page, ChartMeetingType mtgType) { if (UsableSummaryCount(mtgType) > MinChartSeries) { if (_itemFont == null) { throw new InvalidOperationException(nameof(_itemFont)); } var c = new Chart(ChartType.Column2D); c.Font.Name = "Verdana"; var xSeries = c.XValues.AddXSeries(); var ySeries = c.SeriesCollection.AddSeries(); c.YAxis.MaximumScale = LargestDeviationMins; c.YAxis.MinimumScale = -LargestDeviationMins; c.YAxis.LineFormat.Visible = true; c.PlotArea.LineFormat.Visible = true; c.YAxis.MajorTick = 5; c.YAxis.Title.Caption = Resources.OVERTIME_MINS; c.YAxis.Title.Orientation = 90; c.YAxis.Title.VerticalAlignment = PdfSharpCore.Charting.VerticalAlignment.Center; c.YAxis.HasMajorGridlines = true; c.YAxis.MajorGridlines.LineFormat.Color = XColor.FromGrayScale(50); c.YAxis.MajorTickMark = TickMarkType.Outside; c.XAxis.MajorTickMark = TickMarkType.None; switch (mtgType) { case ChartMeetingType.Midweek: c.XAxis.Title.Caption = Resources.MIDWEEK_MTGS; break; case ChartMeetingType.Weekend: c.XAxis.Title.Caption = Resources.WEEKEND_MTGS; break; case ChartMeetingType.Both: c.XAxis.Title.Caption = Resources.MIDWEEK_AND_WEEKEND_MTGS; break; default: throw new NotSupportedException(); } var currentMonth = default(DateTime); if (_historicalASummary != null) { foreach (var summary in _historicalASummary.Summaries) { if (UseSummary(summary, mtgType)) { if (summary.MeetingDate.Year != currentMonth.Year || summary.MeetingDate.Month != currentMonth.Month) { var monthName = summary.MeetingDate.ToString("MMM", CultureInfo.CurrentUICulture); xSeries.Add(monthName); currentMonth = summary.MeetingDate; } else { xSeries.AddBlank(); } var p = ySeries.Add(LimitOvertime(summary.Overtime.TotalMinutes)); p.FillFormat.Color = XColor.FromKnownColor(p.Value > 0 ? XKnownColor.Red : XKnownColor.Green); } } } var frame = new ChartFrame(); var chartHeight = _itemFont.Height * 15; frame.Size = new XSize(page.Width - (_leftMargin * 2), chartHeight); frame.Location = new XPoint(_leftMargin, _currentY); frame.Add(c); frame.DrawChart(g); _currentY += chartHeight + (_itemFont.Height * 2); } }
static void Main(string[] args) { Console.WriteLine("Liczenie częstości występowania pikseli...\n"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //Console.WriteLine("Podaj nazwę obrazka do wczytania"); //string nazwaPliku = Console.ReadLine(); int liczbaWatkow = 8; string sciezka = Directory.GetCurrentDirectory(); string nazwaObrazka = "aaa.jpg"; sciezka += @"\" + nazwaObrazka; //sciezka += @"\" + nazwaPliku; obrazek = new Bitmap(sciezka); obrazki = new Bitmap[liczbaWatkow]; System.Drawing.Imaging.PixelFormat format = obrazek.PixelFormat; Rectangle prostokat; int poczatekSzer; int koniecSzer; int szer; int wys = obrazek.Height; Zakres zakres = new Zakres(); zakres.koniecWys = obrazek.Height; Zakres[] zakresy = new Zakres[liczbaWatkow]; for (int i = 0; i < liczbaWatkow; i++) { poczatekSzer = obrazek.Width / liczbaWatkow * i; if (i != liczbaWatkow - 1) { koniecSzer = obrazek.Width / liczbaWatkow * i + obrazek.Width / liczbaWatkow; } else { koniecSzer = obrazek.Width; } szer = koniecSzer - poczatekSzer; prostokat = new Rectangle(poczatekSzer, 0, szer, wys); obrazki[i] = obrazek.Clone(prostokat, format); zakresy[i].koniecSzer = szer; zakresy[i].koniecWys = obrazek.Height; zakresy[i].numerWatku = i; } slowniki = new Dictionary <Color, int> [liczbaWatkow]; for (int i = 0; i < liczbaWatkow; i++) { slowniki[i] = new Dictionary <Color, int>(); } //Parallel.ForEach(zakresy, (i) => PoliczPiksele(i)); Thread[] watki = new Thread[liczbaWatkow]; for (int i = 0; i < liczbaWatkow; i++) { watki[i] = new Thread(PoliczPiksele); } for (int i = 0; i < liczbaWatkow; i++) { watki[i].Start(zakresy[i]); } for (int i = 0; i < liczbaWatkow; i++) { watki[i].Join(); } Dictionary <Color, int> prawilnySlownik = new Dictionary <Color, int>(); for (int i = 0; i < slowniki.Length; i++) { foreach (var piksel in slowniki[i]) { if (prawilnySlownik.Keys.Contains(piksel.Key)) { prawilnySlownik[piksel.Key] += piksel.Value; } else { prawilnySlownik.Add(piksel.Key, piksel.Value); } } } var posortowany = prawilnySlownik.OrderByDescending(x => x.Value); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Console.WriteLine("Nazwa obrazka: " + nazwaObrazka); Console.WriteLine("Rozmiar obrazka: {0}x{1}", obrazek.Width, obrazek.Height); Console.WriteLine("Suma pikseli: " + obrazek.Width * obrazek.Height); Console.WriteLine("Liczba wątków: " + liczbaWatkow); Console.WriteLine("\nNajczęściej występujące piksele:"); List <string> linieTekstu = new List <string>(); linieTekstu.Add("Nazwa obrazka: " + nazwaObrazka); linieTekstu.Add("Rozmiar obrazka: " + obrazek.Width.ToString() + "x" + obrazek.Height.ToString()); linieTekstu.Add("Suma pikseli: " + obrazek.Width * obrazek.Height); linieTekstu.Add("Liczba wątków: " + liczbaWatkow.ToString()); linieTekstu.Add("Czas wykonania: " + ts.Seconds.ToString() + ":" + ts.Milliseconds.ToString()); linieTekstu.Add(""); linieTekstu.Add("Najczęściej występujące piksele:"); int licznik = 0; foreach (var pixel in posortowany) { licznik++; Console.WriteLine("Piksel nr {4}: [R={0}, G={1}, B={2}], liczba wystąpień: {3}", pixel.Key.R, pixel.Key.G, pixel.Key.B, pixel.Value, licznik); linieTekstu.Add("Piksel nr " + licznik + ": [R=" + pixel.Key.R + ", G=" + pixel.Key.G + ", B=" + pixel.Key.B + "], liczba wystąpień: " + pixel.Value); if (licznik >= 10) { break; } } Console.WriteLine("Czas wykonania: " + ts + "\n"); PdfDocument pdf = new PdfDocument(); PdfPage strona = pdf.AddPage(); XGraphics graf = XGraphics.FromPdfPage(strona); XFont font = new XFont("Calibri", 15); graf.DrawString("Przemysław Prusik", font, XBrushes.Black, new XRect(10, 10, strona.Width.Point, strona.Height.Point), XStringFormats.TopCenter); font = new XFont("Calibri Light", 15); int przesuniecie = 30; foreach (var linia in linieTekstu) { graf.DrawString(linia, font, XBrushes.Black, new XRect(10, przesuniecie, strona.Width.Point, strona.Height.Point), XStringFormats.TopLeft); przesuniecie += 20; } Console.WriteLine("Generowanie pliku pdf...\n"); double[] R = new double[256]; double[] G = new double[256]; double[] B = new double[256]; foreach (var pixel in posortowany) { R[pixel.Key.R] += pixel.Value; G[pixel.Key.G] += pixel.Value; B[pixel.Key.B] += pixel.Value; } Chart histogram = Histogram(R, G, B); ChartFrame ramaHistogramu = new ChartFrame(); ramaHistogramu.Location = new XPoint(50, 40); ramaHistogramu.Size = new XSize(495, 300); ramaHistogramu.Add(histogram); PdfPage strona2 = pdf.AddPage(); XGraphics hist = XGraphics.FromPdfPage(strona2); font = new XFont("Calibri", 15, XFontStyle.Bold); hist.DrawString("Histogram", font, XBrushes.Black, new XRect(10, 10, strona.Width.Point, strona.Height.Point), XStringFormats.TopCenter); ramaHistogramu.Draw(hist); pdf.Save("wyniki.pdf"); Console.WriteLine("Zakończono działanie programu"); Console.ReadKey(); }
public FileContentResult GetRelatorioPDF(int cliente, String de = null, String ate = null) { IQueryable <OSSB> queryObject = _db.OSSB; queryObject = from os in queryObject where os.CLIENTE == cliente select os; if (de != null) { DateTime deDate = DateTime.ParseExact(de, "dd/MM/yyyy", null); if (ate != null) { DateTime ateDate = DateTime.ParseExact(ate, "dd/MM/yyyy", null); queryObject = from os in queryObject where _db.OSSB_CHECK_LIST.Where(oscl => oscl.OSSB == os.ID && oscl.AGENDADO >= deDate && oscl.AGENDADO <= ateDate).Any() select os; } else { queryObject = from os in queryObject where _db.OSSB_CHECK_LIST.Where(oscl => oscl.OSSB == os.ID && oscl.AGENDADO >= deDate).Any() select os; } } else if (ate != null) { DateTime ateDate = DateTime.ParseExact(ate, "dd/MM/yyyy", null); queryObject = from os in queryObject where _db.OSSB_CHECK_LIST.Where(oscl => oscl.OSSB == os.ID && oscl.AGENDADO <= ateDate).Any() select os; } var fs = new MemoryStream(); PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XFont titleFont = new XFont("Times New Roman", 20, XFontStyle.Bold); XFont normalFont = new XFont("Times New Roman", 14, XFontStyle.Bold); ChartFrame cf = new ChartFrame() { Location = new XPoint(page.Width.Point * .05, 60), Size = new XSize(page.Width.Point * .9, page.Width.Point * 0.7) }; Chart chart = new Chart(ChartType.Pie2D); Series series = chart.SeriesCollection.AddSeries(); var queryPreventiva = (from os in queryObject where os.TIPO == "P" group os by (os.SITUACAO == "P" || os.SITUACAO == "K" || os.SITUACAO == "F") ? 0 : 1 into g select new { TIPO = g.Key, QUANTIDADE = g.Count() }).ToDictionary(en => en.TIPO, en => en.QUANTIDADE); series.Add(new double[] { queryPreventiva.GetValueOrDefault(0, 0), queryPreventiva.GetValueOrDefault(1, 0) }); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Realizadas", "Pendentes"); chart.DataLabel.Type = DataLabelType.Value; chart.HasDataLabel = true; chart.Legend.Docking = DockingType.Left; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; cf.Add(chart); XGraphics gfx = XGraphics.FromPdfPage(page); gfx.DrawRectangle(XPens.Black, new XRect(150, 600, (page.Width.Point - 300) * 0.7, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150, 630, (page.Width.Point - 300) * 0.7, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150, 660, (page.Width.Point - 300) * 0.7, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150, 690, (page.Width.Point - 300) * 0.7, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 600, (page.Width.Point - 300) * 0.3, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 630, (page.Width.Point - 300) * 0.3, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 660, (page.Width.Point - 300) * 0.3, 30)); gfx.DrawRectangle(XPens.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 690, (page.Width.Point - 300) * 0.3, 30)); gfx.DrawString("Mês", normalFont, XBrushes.Black, new XRect(150, 600, (page.Width.Point - 300) * 0.7, 30), XStringFormats.Center); gfx.DrawString("Previstas", normalFont, XBrushes.Black, new XRect(150, 630, (page.Width.Point - 300) * 0.7, 30), XStringFormats.Center); gfx.DrawString("Realizadas", normalFont, XBrushes.Black, new XRect(150, 660, (page.Width.Point - 300) * 0.7, 30), XStringFormats.Center); gfx.DrawString("Pendentes", normalFont, XBrushes.Black, new XRect(150, 690, (page.Width.Point - 300) * 0.7, 30), XStringFormats.Center); gfx.DrawString((queryPreventiva.GetValueOrDefault(0, 0) + queryPreventiva.GetValueOrDefault(1, 0)).ToString(), normalFont, XBrushes.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 630, (page.Width.Point - 300) * 0.3, 30), XStringFormats.Center); gfx.DrawString(queryPreventiva.GetValueOrDefault(0, 0).ToString(), normalFont, XBrushes.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 660, (page.Width.Point - 300) * 0.3, 30), XStringFormats.Center); gfx.DrawString((queryPreventiva.GetValueOrDefault(1, 0)).ToString(), normalFont, XBrushes.Black, new XRect(150 + (page.Width.Point - 300) * 0.7, 690, (page.Width.Point - 300) * 0.3, 30), XStringFormats.Center); gfx.DrawString("1. Manutenção Preventiva.", titleFont, XBrushes.Black, new XPoint(10, 25)); cf.Draw(gfx); page = document.AddPage(); gfx = XGraphics.FromPdfPage(page); cf = new ChartFrame() { Location = new XPoint(page.Width.Point * .05, 60), Size = new XSize(page.Width.Point * .9, page.Width.Point * 0.7) }; chart = new Chart(ChartType.Pie2D); var queryCorretiva = (from os in queryObject where os.TIPO == "C" select os) .GroupBy(os => (os.SITUACAO == "P" || os.SITUACAO == "K" || os.SITUACAO == "F") ? 0 : (os.SITUACAO == "E" ? 1 : 2)) .Select(g => new { TIPO = g.Key, QUANTIDADE = g.Count() }) .ToDictionary(os => os.TIPO, os => os.QUANTIDADE); xseries = chart.XValues.AddXSeries(); series = chart.SeriesCollection.AddSeries(); if (queryCorretiva.ContainsKey(0)) { xseries.Add("Executando"); series.Add(queryCorretiva[0]); } if (queryCorretiva.ContainsKey(1)) { xseries.Add("Realizadas"); series.Add(queryCorretiva[1]); } if (queryCorretiva.ContainsKey(2)) { xseries.Add("Emergênciais"); series.Add(queryCorretiva[2]); } chart.DataLabel.Type = DataLabelType.Value; chart.HasDataLabel = true; chart.Legend.Docking = DockingType.Left; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; cf.Add(chart); cf.Draw(gfx); document.Save(fs, false); Response.AppendHeader("Content-Disposition", "inline; filename=relatorio.pdf;"); return(new FileContentResult(fs.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf)); }
public static void ChangePDFChartColor() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Create a page. PdfPage page = document.AddPage(); // Generate a 2d column chart graph Chart chart = new Chart(ChartType.Column2D); Series series = chart.SeriesCollection.AddSeries(); series.Name = "Series 1"; series.Add(new double[] { 1, 5, 3, 20, 11 }); // Set color for 1st series, all the column shapes // in the 1st series will show the same color as 'Gold' series.FillFormat.Color = XColors.Gold; series = chart.SeriesCollection.AddSeries(); series.Name = "Series 2"; series.Add(new double[] { 22, 4, 12, 8, 12 }); // set color for 2nd series, all the column shapes // in the 2nd series will displa the same color as 'Cyan' series.FillFormat.Color = XColors.Cyan; // Set X axes chart.XAxis.TickLabels.Format = "00"; chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; // Set Y axes chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; // Set plot border color chart.PlotArea.LineFormat.Color = XColors.Black; chart.PlotArea.LineFormat.Visible = true; // Set plot background color chart.PlotArea.FillFormat.Color = XColors.White; // Set legend chart.Legend.Docking = DockingType.Right; chart.Legend.LineFormat.Color = XColors.Red; chart.DataLabel.Type = DataLabelType.Value; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; // Create a chart frame, set chart location and size ChartFrame chartFrame = new ChartFrame(); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); chartFrame.Add(chart); // Render chart symbols into pdf page XGraphics g = XGraphics.FromPdfPage(page); chartFrame.Draw(g); // Save and show the document document.Save("ColorChart.pdf"); Process.Start("ColorChart.pdf"); }