public static void DefCharts(Document document) { Paragraph paragraph = document.LastSection.AddParagraph("Chart Overview", "Heading1"); paragraph.AddBookmark("Charts"); document.LastSection.AddParagraph("Sample Chart", "Heading2"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(new double[] { 1, 17, 45, 5, 3, 20, 11, 23, 8, 19 }); series.HasDataLabel = true; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.Add(new double[] { 41, 7, 5, 45, 13, 10, 21, 13, 18, 9 }); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; document.LastSection.Add(chart); }
/// <summary> /// Adds a new XSeries to the collection. /// </summary> public XSeries AddXSeries() { XSeries xSeries = new XSeries(); Add(xSeries); return(xSeries); }
public static void DefCharts(Document document, string info) { document.LastSection.AddParagraph("", "Heading2"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(new double[] { 220, 105, 95, 50, 3, 45, 90, 180, 190, 185 }); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.Black; chart.PlotArea.LineFormat.Width = 1; document.LastSection.Add(chart); var paragraph = document.LastSection.AddParagraph($"\r\n{info}"); paragraph.Format.Alignment = ParagraphAlignment.Center; }
public static Chart LineChart() { Chart chart = new Chart(ChartType.Line); Series series = chart.SeriesCollection.AddSeries(); series.Name = "Time after Index"; series.Add(new double[] { 1, 12, -6, 15, 11 }); //Time after Index series = chart.SeriesCollection.AddSeries(); series.Name = "Time before index"; series.Add(new double[] { 22, 4, 12, 8, 12 });//Time before index chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "Query"; //chart.XAxis.HasMajorGridlines = true; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.Title.Caption = "Time"; chart.YAxis.HasMajorGridlines = true; //chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Color = XColors.Red; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; chart.Legend.Docking = DockingType.Bottom; chart.Legend.LineFormat.Visible = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Q1", "Q2", "Q3", "Q4", "Q5", "Q6"); return(chart); }
public static Chart CombinationChart() { Chart chart = new Chart(); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(new double[] { 1, 17, 45, 5, 3, 20, 11, 23, 8, 19 }); series.HasDataLabel = true; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.Add(new double[] { 41, 7, 5, 45, 13, 10, 21, 13, 18, 9 }); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; chart.Legend.Docking = DockingType.Left; chart.Legend.LineFormat.Visible = true; return(chart); }
/// <summary> /// Initializes the legend's renderer info. Each data point will be represented through /// a legend entry renderer info. /// </summary> internal override RendererInfo Init() { LegendRendererInfo lri = null; ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo; if (cri._chart._legend != null) { lri = new LegendRendererInfo { _legend = cri._chart._legend }; lri.Font = Converter.ToXFont(lri._legend._font, cri.DefaultFont); lri.FontColor = new XSolidBrush(XColors.Black); if (lri._legend._lineFormat != null) { lri.BorderPen = Converter.ToXPen(lri._legend._lineFormat, XColors.Black, DefaultLineWidth, XDashStyle.Solid); } XSeries xseries = null; if (cri._chart._xValues != null) { xseries = cri._chart._xValues[0]; } int index = 0; SeriesRendererInfo sri = cri.seriesRendererInfos[0]; lri.Entries = new LegendEntryRendererInfo[sri._pointRendererInfos.Length]; foreach (PointRendererInfo pri in sri._pointRendererInfos) { LegendEntryRendererInfo leri = new LegendEntryRendererInfo { _seriesRendererInfo = sri, _legendRendererInfo = lri, EntryText = System.String.Empty }; if (xseries != null) { if (xseries.Count > index) { leri.EntryText = xseries[index]._value; } } else { leri.EntryText = (index + 1).ToString(); // create default/dummy entry } leri.MarkerPen = pri.LineFormat; leri.MarkerBrush = pri.FillFormat; lri.Entries[index++] = leri; } } return(lri); }
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 SaveExperimentButton_Click(object sender, RoutedEventArgs e) { YSeries.Insert(YSeries.Count - 1, YSeries.Last()); XSeries.Insert(XSeries.Count - 1, XSeries.Last()); YSpeedSeries.Insert(YSpeedSeries.Count - 1, YSpeedSeries.Last()); XSpeedSeries.Insert(XSpeedSeries.Count - 1, XSpeedSeries.Last()); Parameters.Insert(Parameters.Count - 1, Parameters.Last()); AddEllipse = true; ++colorIndex; Update(); }
private void ListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) { var item = ItemsControl.ContainerFromElement((ItemsControl)sender, (DependencyObject)e.OriginalSource) as ListBoxItem; if (item == null) { return; } var series = (LineSeries)item.Content; if (e.LeftButton == MouseButtonState.Pressed) { series.Visibility = series.Visibility == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; } else if (e.RightButton == MouseButtonState.Pressed) { int index = -1; if (YRadioButton.IsChecked.Value) { index = YSeries.IndexOf(series); } else if (XRadioButton.IsChecked.Value) { index = XSeries.IndexOf(series); } else if (YSpeedRadioButton.IsChecked.Value) { index = YSpeedSeries.IndexOf(series); } else { index = XSpeedSeries.IndexOf(series); } if (index == YSeries.Count - 1) { return; } YSeries.RemoveAt(index); XSeries.RemoveAt(index); YSpeedSeries.RemoveAt(index); XSpeedSeries.RemoveAt(index); AnimCanvas.Children.Remove(Ellipsies[index]); AnimCanvas.Children.Remove(Polylines[index]); Ellipsies.RemoveAt(index); Polylines.RemoveAt(index); YAnimations.RemoveAt(index); XAnimations.RemoveAt(index); Parameters.RemoveAt(index); UpdateAnimation = true; DataChanged = true; } }
/// <summary> /// Создание круговой диаграммы из объекта /// </summary> /// <param name="obj"> Источник данных </param> /// <param name="fileName"> Имя выходного файла </param> public void MakePieChart <T>(List <T> list, string fileName) { if (fileName.Length == 0) { throw new Exception("Не указан путь к файлу"); } var dict = CreateDataSet(list); Document document = new Document(); Style style = document.Styles["Normal"]; style.Font.Name = "Times New Roman"; style.Font.Size = 14; style = document.Styles.AddStyle("NormalTitle", "Normal"); style.Font.Bold = true; Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(""); paragraph.Format.SpaceAfter = "1cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "NormalText"; var chart = document.LastSection.AddChart(ChartType.Pie2D); chart.Left = 0; chart.Width = Unit.FromCentimeter(12); chart.Height = Unit.FromCentimeter(12); chart.DataLabel.Type = dataLabelType; Legend legend = chart.RightArea.AddLegend(); Series series = chart.SeriesCollection.AddSeries(); XSeries xseries = chart.XValues.AddXSeries(); foreach (var key in dict.Keys) { series.Add(dict[key]); xseries.Add(key); } PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always) { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(fileName); }
/// <summary> /// Initializes the rendererInfo's xvalues. If not set by the user xvalues will be simply numbers /// from minimum scale + 1 to maximum scale. /// </summary> private void InitXValues(AxisRendererInfo rendererInfo) { rendererInfo.XValues = ((Chart)rendererInfo._axis._parent)._xValues; if (rendererInfo.XValues == null) { rendererInfo.XValues = new XValues(); XSeries xs = rendererInfo.XValues.AddXSeries(); for (double i = rendererInfo.MinimumScale + 1; i <= rendererInfo.MaximumScale; ++i) { xs.Add(i.ToString()); } } }
private void GetData() { using (var reader = new StreamReader(@"D:\MyData\GithubRepos\Tutorials\GraphingExample\GraphingExample\TestData.csv")) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); XSeries.Add(double.Parse(values[0])); YSeries.Add(double.Parse(values[1])); } } }
public Chart GetPieChart(List <Group> chartGroup) { Chart chart = new Chart(ChartType.Pie2D); Series series = chart.SeriesCollection.AddSeries(); XSeries xseries = chart.XValues.AddXSeries(); for (int i = 0; i < chartGroup.Count; i++) { series.Add(chartGroup[i].GroupValue); xseries.Add(chartGroup[i].GroupName); } return(chart); }
public static Chart PieChart() { Chart chart = new Chart(ChartType.Pie2D); Series series = chart.SeriesCollection.AddSeries(); series.Add(new double[] { 1, 5, 11, -3, 20 }); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Production", "Lab", "Licenses", "Taxes", "Insurances"); chart.Legend.Docking = DockingType.Right; chart.DataLabel.Type = DataLabelType.Percent; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; return(chart); }
public static Chart LineChart() { // Set chart type to line Chart chart = new Chart(ChartType.Line); // Create first series with name and data Series series = chart.SeriesCollection.AddSeries(); series.Name = "Series 1"; series.Add(new double[] { 1, 12, -6, 15, 11 }); // Create second series with name and data series = chart.SeriesCollection.AddSeries(); series.Name = "Series 2"; series.Add(new double[] { 22, 4, 12, 8, 12 }); // Create third series with name and data series = chart.SeriesCollection.AddSeries(); series.Name = "Series 3"; series.Add(new double[] { 12, 17, -3, 18, 1 }); // Set X axes chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; //chart.XAxis.HasMajorGridlines = true; // Set Y axes chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.Title.Caption = "Y-Axis"; chart.YAxis.HasMajorGridlines = true; // Set plot area (chart diagram) chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; // Set legend chart.Legend.Docking = DockingType.Bottom; chart.Legend.LineFormat.Visible = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F"); return(chart); }
static Chart Histogram(double[] R, double[] G, double[] B) { Chart chart = new Chart(ChartType.Line); Series dane = chart.SeriesCollection.AddSeries(); dane.Name = "R"; dane.Add(R); dane.MarkerStyle = MarkerStyle.None; dane.MarkerBackgroundColor = XColor.FromArgb(255, 0, 0); dane = chart.SeriesCollection.AddSeries(); dane.Name = "G"; dane.Add(G); dane.MarkerStyle = MarkerStyle.None; dane.MarkerBackgroundColor = XColor.FromArgb(0, 255, 0); dane = chart.SeriesCollection.AddSeries(); dane.Name = "B"; dane.Add(B); dane.MarkerStyle = MarkerStyle.None; dane.MarkerBackgroundColor = XColor.FromArgb(0, 0, 255); chart.XAxis.Title.Caption = "nasycenie"; chart.YAxis.Title.Caption = "liczba wystąpień"; chart.YAxis.HasMajorGridlines = true; chart.Legend.Docking = DockingType.Right; XSeries xseries = chart.XValues.AddXSeries(); for (int i = 0; i < 256; i++) { if (i % 51 == 0) { xseries.Add(i.ToString()); } else { xseries.Add(""); } } return(chart); }
/// <summary> /// Calculates the space used for the X axis. /// </summary> internal override void Format() { AxisRendererInfo xari = ((ChartRendererInfo)_rendererParms.RendererInfo).xAxisRendererInfo; if (xari._axis != null) { AxisTitleRendererInfo atri = xari._axisTitleRendererInfo; // Calculate space used for axis title. XSize titleSize = new XSize(0, 0); if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { titleSize = _rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); atri.AxisTitleSize = titleSize; } // Calculate space used for tick labels. XSize size = new XSize(0, 0); if (xari.XValues.Count > 0) { XSeries xs = xari.XValues[0]; foreach (XValue xv in xs) { if (xv != null) { string tickLabel = xv._value; XSize valueSize = _rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont); XRect rect = new XRect(new XPoint(0, 0), valueSize); rect.Transform(RotateByDegrees(xari._axis.TickLabelAngle, rect.Center)); valueSize = rect.Size; size.Height = Math.Max(valueSize.Height, size.Height); size.Width += valueSize.Width; } } } // Remember space for later drawing. xari.TickLabelsHeight = size.Height; xari.Height = titleSize.Height + size.Height + xari.MajorTickMarkWidth; xari.Width = Math.Max(titleSize.Width, size.Width); } }
private void Fill() { Section section = _document.AddSection(); Paragraph par = _document.LastSection.AddParagraph("Цены самых продаваемых товаров", "Header"); par.Format.Alignment = ParagraphAlignment.Center; section.AddParagraph().AddLineBreaks(3); // Chart chart = new Chart(); chart.Left = 0; // chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(furnitures.Select(f => (double)f.Price).ToArray()); series.HasDataLabel = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(Enumerable.Range(1, furnitures.Count()).Select(n => n.ToString()).ToArray()); chart.XAxis.MajorTickMark = TickMarkType.Outside; // chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; _document.LastSection.Add(chart); par = _document.LastSection.AddParagraph(); par.AddLineBreaks(2); par.AddTextLine("Легенда:"); int i = 1; foreach (var f in furnitures) { par.AddTextLine(i.ToString() + " = " + "[" + f.VendorCode + "] " + f.Name); i++; } }
public static void SpeciesPicturesInProject_PieChart(Document document, Project currentProject) { try { General_queries projq = new General_queries(currentProject); List <SpeciesStats> stats = projq.AllStatsBySpecies; double[] speciesPictures = new double[stats.Count]; string[] speciesNames = new string[stats.Count]; double speciesSum = 0; for (int i = 0; i < stats.Count; i++) { speciesSum += stats[i].SpeciesPictures; speciesPictures[i] = stats[i].SpeciesPictures; speciesNames[i] = stats[i].SpeciesName; } document.LastSection.AddParagraph("Pictures in project where the species appears", "Heading2"); Chart chart = new Chart(); chart.Type = ChartType.Pie2D; chart.Left = 0; chart.Width = Unit.FromCentimeter(10); chart.Height = Unit.FromCentimeter(8); Series series = chart.SeriesCollection.AddSeries(); series.Add(speciesPictures); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(speciesNames); chart.RightArea.AddLegend(); chart.DataLabel.Type = DataLabelType.Percent; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; document.LastSection.Add(chart); } catch (Exception ex) { throw ex; } }
void MapObject(XValues xValues, DocumentObjectModel.Shapes.Charts.XValues domXValues) { foreach (DocumentObjectModel.Shapes.Charts.XSeries domXSeries in domXValues) { XSeries xSeries = xValues.AddXSeries(); DocumentObjectModel.Shapes.Charts.XSeriesElements domXSeriesElements = domXSeries.GetValue("XSeriesElements") as DocumentObjectModel.Shapes.Charts.XSeriesElements; foreach (DocumentObjectModel.Shapes.Charts.XValue domXValue in domXSeriesElements) { if (domXValue == null) { xSeries.AddBlank(); } else { xSeries.Add(domXValue.GetValue("Value").ToString()); } } } }
private void TRTB_TextChanged(object sender, TextChangedEventArgs e) { if (AnimCanvas != null) { AnimCanvas.Children.Clear(); AnimCanvas.Children.Add(XAxis); AnimCanvas.Children.Add(YAxis); } YSeries.Clear(); XSeries.Clear(); YSpeedSeries.Clear(); XSpeedSeries.Clear(); Ellipsies.Clear(); Polylines.Clear(); YAnimations.Clear(); XAnimations.Clear(); Parameters.Clear(); AddEllipse = true; colorIndex = 0; TB_TextChanged(sender, e); }
public static void SpeciesTimeBehavior_BarChart(Document document, Project currentProject) { try { General_queries projq = new General_queries(currentProject); foreach (SpeciesStats spst in projq.AllStatsBySpecies) { document.LastSection.AddParagraph(spst.SpeciesName + " Activity Patterns", "Heading2"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(spst.ActivityPatern); series.HasDataLabel = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "Hours of day"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.YAxis.MajorGridlines.LineFormat.Color = Colors.DarkGray; chart.YAxis.Title.Caption = "Freq"; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; document.LastSection.Add(chart); } } catch (Exception ex) { throw ex; } }
public static Chart LineChart() { Chart chart = new Chart(ChartType.Line); Series series = chart.SeriesCollection.AddSeries(); series.Name = "Series 1"; series.Add(new double[] { 1, 5, -3, 20, 11 }); series = chart.SeriesCollection.AddSeries(); series.Name = "Series 2"; series.Add(new double[] { 22, 4, 12, 8, 12 }); series = chart.SeriesCollection.AddSeries(); series.Name = "Series 3"; series.Add(new double[] { 12, 14, -3, 18, 1 }); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.Title.Caption = "Y-Axis"; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; chart.Legend.Docking = DockingType.Bottom; chart.Legend.LineFormat.Visible = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F"); return(chart); }
public static Chart PieChart() { // Set chart type to Pie2D Chart chart = new Chart(ChartType.Pie2D); // Add series data Series series = chart.SeriesCollection.AddSeries(); series.Add(new double[] { 1, 5, 11, 3, 20 }); // Add series legend XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("Series 1", "Series 2", "Series 3", "Series 4", "Series 5"); chart.Legend.Docking = DockingType.Right; // Set label display type chart.DataLabel.Type = DataLabelType.Percent; // Set label location chart.DataLabel.Position = DataLabelPosition.Center; return(chart); }
// define the charting page for the resistance values static void DefineResistanceChart(Document document) { Paragraph paragraph = document.LastSection.AddParagraph("Battery Resistance Chart", "Heading1"); //paragraph.AddBookmark("ResistanceChart"); paragraph = document.LastSection.AddParagraph("Cell Resistances", "Heading2"); paragraph.Format.OutlineLevel = OutlineLevel.BodyText; Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; // create an array of all the battery cell voltages and cell numbers to use as values List <double> resistanceValuesList = new List <double>(); List <string> cellXlabels = new List <string>(); // depending on the number of cells, need to suss out a gap say every 10% int xSpacing = (int)(currentResult.cellReadingsList.Count * 0.1); if (xSpacing < 1) { xSpacing = 1; } foreach (CellReading reading in currentResult.cellReadingsList) { //add the resistance values to the table series resistanceValuesList.Add(reading.resistance); // add the corresponding x labelling to the series, but try and space them out if theres alot if (reading.cellNumber % xSpacing == 0) { cellXlabels.Add(reading.cellNumber.ToString()); //Console.WriteLine(reading.cellNumber.ToString()); } else { cellXlabels.Add(""); } } // now add the voltage data to the chart series series.Add(resistanceValuesList.ToArray()); series.HasDataLabel = false; // now to color the bar graph for the resistance values depending on the current test thresholds var elements = series.Elements.Cast <Point>().ToArray(); // since each of the elements will be the same index as the readings, loop through and color accordingly int counterIndex = 0; foreach (CellReading reading in currentResult.cellReadingsList) { if (currentResult.lowResistance_threshold == currentResult.highResistance_threshold) { elements[counterIndex].FillFormat.Color = Colors.Blue; } else if (reading.resistance > currentResult.highResistance_threshold) { elements[counterIndex].FillFormat.Color = Colors.Red; } else if (reading.resistance < currentResult.lowResistance_threshold) { elements[counterIndex].FillFormat.Color = Colors.Yellow; } else { elements[counterIndex].FillFormat.Color = Colors.Blue; } counterIndex++; } // create the xlabel series and add the cell numbers XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(cellXlabels.ToArray()); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "Cell Numbers"; // y values min and max double yMin, yMax; yMin = currentResult.GetMinResistanceValueAsDouble(); yMax = currentResult.GetMaxResistanceValueAsDouble(); chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTick = (yMax - yMin) * 0.1; //chart.YAxis.TickLabels.Format = "0"; chart.YAxis.HasMajorGridlines = true; // now to set up the Y axis scales, need to get the min and max floats and put a small tollerance either side // just so that the min and max values arent slap bang on the axis lines double chartYAxisPadding = (yMax - yMin) * 0.1; // just 10 percent padding for min and max charting values chart.YAxis.MinimumScale = currentResult.GetMinResistanceValueAsDouble() - chartYAxisPadding; chart.YAxis.MaximumScale = currentResult.GetMaxResistanceValueAsDouble() + chartYAxisPadding; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; document.LastSection.Add(chart); }
/// <summary> /// Adds a new XSeries to the collection. /// </summary> public XSeries AddXSeries() { XSeries xSeries = new XSeries(); Add(xSeries); return xSeries; }
private static void DefineCharts(Document document, string person, Dictionary <string, string[]> groups, DataHandler datahandler) { List <double[]> list = new List <double[]>(); List <String> names = new List <string>(); YearInfo year = datahandler.GetYear(datahandler.FirstAvailableYear); /***** Calculate series data ******/ foreach (KeyValuePair <string, string[]> pair in groups) { String[] kgms = pair.Value; double[] percentages = new double[12]; names.Add(pair.Key); for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { percentages[i] = sm.PercentOfTotal(kgms); } else { percentages[i] = 0; } } else { percentages[i] = 0; } } list.Add(percentages); } double[] oms = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { oms[i] = sm.Omsaetning; } else { oms[i] = 0; } } else { oms[i] = 0; } } double[] ind = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { ind[i] = sm.Indtjening; } else { ind[i] = 0; } } else { ind[i] = 0; } } /***** Create chart for omsætning/indtjening series ******/ MigraDoc.DocumentObjectModel.Paragraph paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); MigraDoc.DocumentObjectModel.Shapes.Charts.Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(oms); series.SetNull(); series.Name = "Omsætning"; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(ind); series.SetNull(); series.Name = "Indtjening"; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); /***** Create chart for KGM series ******/ paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); for (int i = 0; i < list.Count; i++) { series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(list[i]); series.SetNull(); series.Name = names[i]; } xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.TickLabels.Format = "#0%"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); }
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)); }
private Chart GenerateOneEquityChart(List <VMDynamics> lstVMDyn, DateTime dtBegin, DateTime dtEnd) { Chart chart = new Chart(); chart.XAxis.MajorTick = 10; chart.Left = 0; chart.Width = Unit.FromCentimeter(19); chart.Height = Unit.FromCentimeter(8); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.HasDataLabel = true; XSeries xseries = chart.XValues.AddXSeries(); List <string> lstDt = new List <string>(); // DateTime dtBegin = ((DateTime) _reportData.DataStockExchResultsTable["DtBegin"]); //DateTime dtBegin = new DateTime(2016, 9, 22, 10, 0, 0); // DateTime dtEnd = new DateTime(2016, 9, 22, 18, 45, 0); CVMDynDataTraceGenerator vmproc = new CVMDynDataTraceGenerator(_reportData.ListVMDynamics); List <string> lstOutX; List <double> lstOutY; vmproc.GetVMTrendList(dtBegin, dtEnd, 10, 0, out lstOutX, out lstOutY); series.Add(lstOutY.ToArray()); xseries.Add(lstOutX.ToArray()); //int[] arr = new string[] { "10:00", 5, 10, 15, 21 }; // xseries.Add(arr); //xseries.Add(new string[] { new DateTime(2016, 9, 1,0,0,0).ToString("HH:mm") , new DateTime(2016, 9, 1, 0,10,0).ToString("HH:mm") }); // chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.HasMajorGridlines = true; chart.XAxis.HasMinorGridlines = true; chart.SeriesCollection[0].MarkerSize = 2; chart.SeriesCollection[0].LineFormat.Width = 1.0; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMinorGridlines = true; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; return(chart); }
/// <summary> /// Calculates the space used for the X axis. /// </summary> internal override void Format() { AxisRendererInfo xari = ((ChartRendererInfo)this.rendererParms.RendererInfo).xAxisRendererInfo; if (xari.axis != null) { AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; // Calculate space used for axis title. XSize titleSize = new XSize(0, 0); if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { titleSize = this.rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); atri.AxisTitleSize = titleSize; } Chart chart = (Chart)this.rendererParms.DrawingItem; XSize size = new XSize(0, 0); bool isxy = false; Series s = chart.seriesCollection[0]; if (s != null && s.Elements.getPointX(0) != null) { isxy = true; // width of all ticklabels double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double lineHeight = Double.MinValue; XSize labelSize = new XSize(0, 0); XGraphics gfx = this.rendererParms.Graphics; for (double x = xMin; x <= xMax; x += xMajorTick) { string str = x.ToString(xari.TickLabelsFormat); labelSize = gfx.MeasureString(str, xari.TickLabelsFont); size.Width += labelSize.Width; size.Height = Math.Max(size.Height, labelSize.Height); lineHeight = Math.Max(lineHeight, labelSize.Height); } // add space for tickmarks size.Width += xari.MajorTickMarkWidth * 1.5; } if (!isxy) { // Calculate space used for tick labels. if (xari.XValues.Count > 0) { XSeries xs = xari.XValues[0]; foreach (XValue xv in xs) { if (xv != null) { string tickLabel = xv.Value; XSize valueSize = this.rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont); size.Height = Math.Max(valueSize.Height, size.Height); size.Width += valueSize.Width; } } } // Remember space for later drawing. xari.TickLabelsHeight = size.Height; xari.Height = titleSize.Height + size.Height + xari.MajorTickMarkWidth; xari.Width = Math.Max(titleSize.Width, size.Width); } } }
public PdfSharp.Charting.Chart LineChart() { List <Activity> filteredProfitExpenses; if (SelectedType.Equals(Constants.PROFIT)) { if (!SelectedCategory.Equals(Constants.ALL_DATA)) { List <Activity> profits = profitActivities.Where(p => p.category.Equals(SelectedCategory)).ToList(); filteredProfitExpenses = filterPeriod(profits); } else { filteredProfitExpenses = filterPeriod(profitActivities); } } else if (SelectedType.Equals(Constants.EXPENSE)) { if (!SelectedCategory.Equals(Constants.ALL_DATA)) { List <Activity> expenses = expenseActivities.Where(p => p.category.Equals(SelectedCategory)).ToList(); filteredProfitExpenses = filterPeriod(expenses); } else { filteredProfitExpenses = filterPeriod(expenseActivities); } } else { filteredProfitExpenses = filterPeriod(profitExpenses); } PdfSharp.Charting.Chart chart = new PdfSharp.Charting.Chart(ChartType.Line); Series series; if (filteredProfitExpenses.Find(o => o.type.Equals(Constants.PROFIT)) != null) { series = chart.SeriesCollection.AddSeries(); series.Name = "Profit"; series.Add(filteredProfitExpenses .Where(o => o.type.Equals(Constants.PROFIT)).ToList() .ConvertAll(o => o.amount).ToArray()); } if (filteredProfitExpenses.Find(o => o.type.Equals(Constants.EXPENSE)) != null) { series = chart.SeriesCollection.AddSeries(); series.Name = "Expense"; series.Add(filteredProfitExpenses .Where(o => o.type.Equals(Constants.EXPENSE)).ToList() .ConvertAll(o => o.amount).ToArray()); } chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "Date"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.Title.Caption = "Amount"; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; chart.Legend.Docking = DockingType.Bottom; chart.Legend.LineFormat.Visible = true; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(filteredProfitExpenses.ConvertAll(o => o.dateTime.ToShortDateString()).ToArray()); return(chart); }