This C# tutorial demonstrates how to create the Microsoft Range Chart (both 2D and 3D style Range Chart), and insert the MS Range Chart as image to PDF Page.
Each data point in the series has a high y-value and a low y-value, the range chart shows the visual view between such two values. The following C# .NET demo code shows how to create and save Microsoft Range 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)
Generate and save Microsoft 2D 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 range chart stream object Stream chartStream = CreateMSRangeChart(); // 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("MSRangeChart.pdf"); Process.Start("MSRangeChart.pdf"); } public static Stream CreateMSRangeChart() { // 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.Range; 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.Range; 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; }
Render and paint MS 3D Range 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 "CreateMSRangeChart()" 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
- Exporting Microsoft 100% Stacked Column graphs to PDF using .NET and XsPDF Toolkit
- Microsoft Polar chart saved to PDF document - C# demo
- MS Range Column diagram converted to PDF document - Visual C# guide
- MS Range Bar graphs inserted to PDF document - C#.NET online tutorial
- How to use XsPDF Component for .NET to insert Microsoft Point chart to PDF page in Visual Studio .NET framework
- MS 100% Stacked Bar diagram made to PDF document - CSharp .NET tutorial
- How to convert Microsoft Pie graphs to PDF document in WPF using .NET Visual C#
- Microsoft Radar graphs added to PDF document - .NET C# tutorial
- Saving MS Stacked Column graphs to PDF using .NET Visual C# and XsPDF Library
- MS Line graphing drawn to PDF document - Visual C# online guide
- MS Funnel chart painted to PDF document - C# tutorial
- Generate Microsoft Range diagram to PDF in CSharp .NET
- C#.NET online tutorial for creation MS Spline Range diagram to PDF file
- Microsoft Stacked Bar diagram converted to PDF document - C# demo
- How to use XsPDF Toolkit for .NET to draw Microsoft Bar graphs to PDF page in .NET