This C# tutorial demonstrates how to generate the Microsoft Spline Range Chart (both 2D and 3D Spline Range Chart), and insert the MS Spline Range Chart image to PDF Page.
Each point of spline range chart contains two values (start and stop value). The following C# .NET sample shows how to create and save Microsoft Spline Range Chart to PDF document programmatically.
Please note, before developers using the chart making code, the MS Chart Control should be added referrence to your .NET application:
- System.Windows.Forms.DataVisualization.Charting (for .NET WinForms program)
- System.Web.UI.DataVisualization.Charting (for ASP.NET application)
Render and draw Microsoft 2D Spline Range 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 spline range chart stream object Stream chartStream = CreateMSSplineRangeChart(); // 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("MSSplineRangeChart.pdf"); Process.Start("MSSplineRangeChart.pdf"); } public static Stream CreateMSSplineRangeChart() { // Create ms chart object Chart chart = new Chart(); ChartArea chartArea = new ChartArea(); Series series1 = new Series(); // Bind series data to chart // If use range chart type, need bind the series to chart first chart.Series.Add(series1); chart.Series.Add(series2); // Input Data Point double[] yValue11 = { 56, 74, 45, 59, 34, 87, 50, 87, 64, 34 }; double[] yValue12 = { 42, 65, 30, 42, 25, 47, 40, 70, 34, 20 }; double[] yValue21 = { 26, 54, 35, 79, 64, 37, 70, 67, 34, 74 }; double[] yValue22 = { 12, 6, 23, 34, 15, 27, 60, 30, 24, 50 }; // Set series1 with data, color, chart type and name series1.BorderColor = Color.FromArgb(180, 26, 59, 105); series1.ChartType = SeriesChartType.SplineRange; series1.Color = Color.FromArgb(180, 65, 140, 240); series1.Name = "Series1"; series1.Points.DataBindY(yValue11, yValue12); // Set series2 with data, color, chart type and name series2.BorderColor = Color.FromArgb(180, 26, 59, 105); series2.ChartType = SeriesChartType.SplineRange; series2.Color = Color.FromArgb(220, 252, 180, 65); series2.Name = "Series2"; series2.Points.DataBindY(yValue21, yValue22); // 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; }
Create and insert MS 3D Spline Range Chart to PDF in C# code.
All the steps are the same as above, only need change one line code chartArea.Area3DStyle.Enable3D = false; in the "CreateMSSplineRangeChart()" 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
- Microsoft Line graphs painting to PDF in CSharp .NET is quite easy and quick using XsPDF SDK for .NET
- How to make Microsoft 100% Stacked Column diagram to PDF document in ASP.NET AJAX using .NET Visual C#
- How to insert MS 100% Stacked Bar graphing to PDF document in Azure cloud service using C#.NET
- How to use XsPDF DLL for .NET to export MS Stacked Area chart to PDF page in Visual Studio .NET framework
- How to use XsPDF DLL for .NET to save MS Funnel diagram to PDF page in C#
- Create Microsoft Bubble chart to PDF in C#.NET
- How to paint Microsoft Range Bar graphing to PDF document in ASP.NET using Visual Studio .NET framework
- Create Microsoft Spline Range graphs to PDF in Visual Studio .NET framework
- Microsoft Range Column graphs creation to PDF in C#.NET is quite easy and quick using XsPDF Component for .NET
- Visual C# online sample for making Microsoft Pyramid diagram to PDF file
- How to use XsPDF Component for .NET to create Microsoft Area chart to PDF page in .NET Visual C#
- How to make Microsoft Bar chart to PDF document in ASP.NET using Visual Studio .NET framework
- Add MS Point chart to PDF in CSharp .NET
- Generate Microsoft Radar chart to PDF in C#
- Microsoft Pie graphs converted to PDF document - CSharp .NET online sample