/// <summary>Creates the graph.</summary> /// <param name="writer">The writer.</param> /// <param name="graphAndTable">The graph and table to convert to html.</param> /// <param name="workingDirectory">The working directory.</param> private void CreateGraphPDF(Section section, AutoDocumentation.GraphAndTable graphAndTable, string workingDirectory) { // Create a 2 column, 1 row table. Image in first cell, X/Y data in second cell. Table table = section.AddTable(); table.Style = "GraphAndTable"; table.Rows.LeftIndent = graphAndTable.indent + "cm"; Column column1 = table.AddColumn(); column1.Width = "8cm"; //column1.Format.Alignment = ParagraphAlignment.Right; Column column2 = table.AddColumn(); column2.Width = "8cm"; //column2.Format.Alignment = ParagraphAlignment.Right; Row row = table.AddRow(); // Ensure graphs directory exists. string graphDirectory = Path.Combine(workingDirectory, "Graphs"); Directory.CreateDirectory(graphDirectory); // Determine the name of the .png file to write. string PNGFileName = Path.Combine(graphDirectory, graphAndTable.xyPairs.Parent.Parent.Name + graphAndTable.xyPairs.Parent.Name + ".png"); // Setup graph. GraphView graph = new GraphView(); graph.Clear(); // Create a line series. graph.DrawLineAndMarkers("", graphAndTable.xyPairs.X, graphAndTable.xyPairs.Y, Models.Graph.Axis.AxisType.Bottom, Models.Graph.Axis.AxisType.Left, System.Drawing.Color.Blue, Models.Graph.LineType.Solid, Models.Graph.MarkerType.None, Models.Graph.LineThicknessType.Normal, Models.Graph.MarkerSizeType.Normal, true); // Format the axes. graph.FormatAxis(Models.Graph.Axis.AxisType.Bottom, graphAndTable.xName, false, double.NaN, double.NaN, double.NaN); graph.FormatAxis(Models.Graph.Axis.AxisType.Left, graphAndTable.yName, false, double.NaN, double.NaN, double.NaN); graph.BackColor = System.Drawing.Color.White; graph.FontSize = 10; graph.Refresh(); // Export graph to bitmap file. Bitmap image = new Bitmap(400, 250); graph.Export(image, false); image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); MigraDoc.DocumentObjectModel.Shapes.Image image1 = row.Cells[0].AddImage(PNGFileName); // Add x/y data. Paragraph xyParagraph = row.Cells[1].AddParagraph(); xyParagraph.Style = "xyStyle"; AddFixedWidthText(xyParagraph, "X", 10); AddFixedWidthText(xyParagraph, "Y", 10); xyParagraph.AddLineBreak(); for (int i = 0; i < graphAndTable.xyPairs.X.Length; i++) { AddFixedWidthText(xyParagraph, graphAndTable.xyPairs.X[i].ToString(), 10); AddFixedWidthText(xyParagraph, graphAndTable.xyPairs.Y[i].ToString(), 10); xyParagraph.AddLineBreak(); } // Add an empty paragraph for spacing. Paragraph spacing = section.AddParagraph(); }