This C# tutorial demonstrates how to make the Microsoft Range Column Chart (both 2D and 3D style Range Column Chart), and insert the MS Range Column Chart as image to PDF Page.
Range Column chart usually works with time period, it shows one process's start/stop time. The following C# .NET demo code shows how to create and save Microsoft Range Column 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 Column 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-column chart stream object Stream chartStream = CreateMSRangeColumnChart(); // 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("MSRangeColumnChart.pdf"); Process.Start("MSRangeColumnChart.pdf"); } public static Stream CreateMSRangeColumnChart() { // 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); DateTime currentData = DateTime.Now.Date; // Set series1 with data, color, chart type and name series1.BorderColor = Color.FromArgb(180, 26, 59, 105); series1.ChartType = SeriesChartType.RangeColumn; series1.Color = Color.FromArgb(180, 65, 140, 240); series1.Name = "Series1"; series1.Points.AddXY(2, currentData, currentData.AddDays(4)); series1.Points.AddXY(4, currentData.AddDays(5), currentData.AddDays(7)); series1.Points.AddXY(3, currentData.AddDays(8), currentData.AddDays(10)); series1.Points.AddXY(1, currentData.AddDays(12), currentData.AddDays(15)); series1.Points.AddXY(4, currentData.AddDays(17), currentData.AddDays(22)); // Set series2 with data, color, chart type and name series2.BorderColor = Color.FromArgb(180, 26, 59, 105); series2.ChartType = SeriesChartType.RangeColumn; series2.Color = Color.FromArgb(220, 252, 180, 65); series2.Name = "Series2"; series2.Points.AddXY(1, currentData, currentData.AddDays(4)); series2.Points.AddXY(2, currentData.AddDays(5), currentData.AddDays(7)); series2.Points.AddXY(3, currentData.AddDays(8), currentData.AddDays(10)); series2.Points.AddXY(5, currentData.AddDays(12), currentData.AddDays(13)); series2.Points.AddXY(2, currentData.AddDays(12), currentData.AddDays(16)); // 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; }
Make and insert MS 3D Range Column 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 "CreateMSRangeColumnChart()" 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
- Convert Microsoft Polar graphs to PDF in .NET C#
- How to add MS Funnel graphs to PDF document in WPF using .NET
- Microsoft Range Column chart painted to PDF document - Visual C# online guide
- Paint Microsoft Line chart to PDF in C#
- Add Microsoft Range graphing to PDF in C#
- CSharp .NET demo for creating Microsoft Stacked100 Column chart to PDF file
- Microsoft Column chart created to PDF document - C# online sample
- Make Microsoft Stacked Column diagram to PDF in C#.NET
- How to make MS Bar chart to PDF document in ASP.NET MVC using .NET C#
- MS Spline Range graphs painting to PDF in .NET is quite easy and quick using XsPDF DLL for .NET
- Creating MS Area chart to PDF using CSharp .NET and XsPDF Component
- MS Bubble chart saving to PDF in .NET is quite easy and quick using XsPDF source code for .NET
- Microsoft Stacked Area diagram painting to PDF in C# is quite easy and quick using XsPDF Toolkit for .NET
- MS Stacked Bar chart saving to PDF in .NET is quite easy and quick using XsPDF SDK for .NET
- How to export Microsoft Range Bar graphing to PDF document in Console Application using CSharp .NET