This C# tutorial demonstrates how to generate the Microsoft Point Chart (both 2D and 3D style Point Chart), and insert the MS Point Chart as image to PDF Page.
Developers can set several groups of data in Point chart, and each group points can be modified in different show style, such as Circle and Square. The following C# .NET demo code shows how to create and save Microsoft Point Chart to PDF document programmatically.
Please note, before developers using the chart making code, the MS Chart Control should be referred to your .NET application:
- System.Windows.Forms.DataVisualization.Charting (for .NET WinForms project)
- System.Web.UI.DataVisualization.Charting (for ASP.NET application)
Draw and insert Microsoft 2D Point Chart to PDF in C# code.
public static void InsertMSChartToPDF() { // Create a new PDF document. PdfDocument document = new PdfDocument(); // Create an empty page in this document. PdfPage page = document.AddPage(); // Obtain an XGraphics object to render to XGraphics g = XGraphics.FromPdfPage(page); // Create point chart stream object Stream chartStream = CreateMSPointChart(); // Convert chart stream to XImage object XImage chartImage = XImage.FromStream(chartStream); // Insert the chart image to pdf page in any position g.DrawImage(chartImage, 50, 50); // Save and show the document document.Save("MSPointChart.pdf"); Process.Start("MSPointChart.pdf"); } public static Stream CreateMSPointChart() { // Create ms chart object Chart chart = new Chart(); ChartArea chartArea = new ChartArea(); Series series1 = new Series(); Series series2 = new Series(); // Input Data Point DataPoint dataPoint1 = new DataPoint(0, 5); DataPoint dataPoint2 = new DataPoint(0, 8.5); DataPoint dataPoint3 = new DataPoint(0, 9); DataPoint dataPoint4 = new DataPoint(0, 7); DataPoint dataPoint5 = new DataPoint(0, 5); DataPoint dataPoint6 = new DataPoint(0, 6); DataPoint dataPoint7 = new DataPoint(0, 4); DataPoint dataPoint8 = new DataPoint(0, 5); DataPoint dataPoint9 = new DataPoint(0, 3.5); DataPoint dataPoint10 = new DataPoint(0, 4); // Set series1 with data, color, chart type and name series1.BorderColor = Color.FromArgb(180, 26, 59, 105); series1.ChartType = SeriesChartType.Point; series1.Color = Color.FromArgb(220, 65, 140, 240); series1.Name = "Series1"; series1.MarkerSize = 10; series1.MarkerStyle = MarkerStyle.Circle; series1.Points.Add(dataPoint1); series1.Points.Add(dataPoint2); series1.Points.Add(dataPoint3); series1.Points.Add(dataPoint4); series1.Points.Add(dataPoint5); // Set series2 with data, color, chart type and name series2.BorderColor = Color.FromArgb(180, 26, 59, 105); series2.ChartType = SeriesChartType.Point; series2.Color = Color.FromArgb(220, 252, 180, 65); series2.Name = "Series2"; series2.MarkerSize = 10; series2.MarkerStyle = MarkerStyle.Square; series2.Points.Add(dataPoint6); series2.Points.Add(dataPoint7); series2.Points.Add(dataPoint8); series2.Points.Add(dataPoint9); series2.Points.Add(dataPoint10); // Bind series data to chart chart.Series.Add(series1); chart.Series.Add(series2); // Set chart 3D style chartArea.Area3DStyle.Enable3D = false; // Bind chart area to chart object chart.ChartAreas.Add(chartArea); // Modify chart size chart.Size = new Size(400, 300); // Render chart graphics to stream MemoryStream ms = new MemoryStream(); chart.SaveImage(ms, ChartImageFormat.Png); return ms; }
Generate and render MS 3D Point Chart to PDF in C# code.
All the step and code are the same as above, only need change the chartArea.Area3DStyle.Enable3D = false; in the "CreateMSPointChart()" to the C# code below.
chartArea.Area3DStyle.Enable3D = true; chartArea.Area3DStyle.Inclination = 15; chartArea.Area3DStyle.IsRightAngleAxes = false; chartArea.Area3DStyle.Perspective = 10; chartArea.Area3DStyle.Rotation = 10; chartArea.BackColor = Color.WhiteSmoke;
More MS Chart to PDF tutorial
- How to convert MS Spline Range graphs to PDF document in Winform program using Visual Studio .NET framework
- Painting MS Pyramid diagram to PDF using .NET C# and XsPDF Toolkit
- How to save MS Bar graphs to PDF document in ASP.NET program using C#.NET
- Microsoft Polar graphs drawn to PDF document - Visual C# guide
- MS Point chart saving to PDF in C# is quite easy and quick using XsPDF Control for .NET
- How to insert MS Area graphing to PDF document in ASP.NET web page using Visual C#
- .NET Visual C# online sample for creation MS Pie chart to PDF file
- How to use XsPDF source code for .NET to export MS Stacked Area diagram to PDF page in .NET
- Paint Microsoft Range chart to PDF in Visual C#
- Microsoft Stacked Column diagram drawn to PDF document - Visual Studio .NET framework sample code
- How to use XsPDF SDK for .NET to insert MS Doughnut graphs to PDF page in .NET C#
- How to use XsPDF Toolkit for .NET to convert MS Spline Area chart to PDF page in CSharp .NET
- MS Bubble diagram created to PDF document - C#.NET online sample
- .NET C# sample code for creation MS 100% Stacked Bar graphing to PDF file
- Insert MS Radar graphs to PDF in .NET C#