This C# tutorial demonstrates how to generate the Microsoft Range Bar Chart (contains 2D and 3D types), and insert the MS Range Bar Chart image to PDF file.
Range Bar chart always used in progress graph, it can take a good view to project schedule. The following C# .NET demo code shows how to create and save Microsoft Range Bar Chart to PDF document programmatically.
Please note, before developers using the chart creating 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 Bar 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-bar chart stream object Stream chartStream = CreateMSRangeBarChart(); // 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("MSRangeBarChart.pdf"); Process.Start("MSRangeBarChart.pdf"); } public static Stream CreateMSRangeBarChart() { // 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.RangeBar; 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.RangeBar; 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 save MS 3D Range Bar 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 "CreateMSRangeBarChart()" 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
- Painting MS Range Bar diagram to PDF using .NET and XsPDF source code
- Making Microsoft Bubble chart to PDF using Visual C# and XsPDF source code
- Drawing Microsoft Pie chart to PDF using .NET and XsPDF Library
- How to use XsPDF SDK for .NET to make Microsoft Spline Area diagram to PDF page in C#
- Making MS Radar diagram to PDF using Visual C# and XsPDF DLL
- How to generate Microsoft Area graphs to PDF document in Azure cloud service using .NET
- Adding MS Stacked100 Bar graphing to PDF using CSharp .NET and XsPDF DLL
- Microsoft Point chart created to PDF document - CSharp .NET sample code
- How to paint Microsoft Column diagram to PDF document in Console Application using Visual Studio .NET framework
- Paint Microsoft Stacked Column graphing to PDF in Visual Studio .NET framework
- How to generate Microsoft Stacked Area graphs to PDF document in ASP.NET AJAX using .NET Visual C#
- Generate Microsoft Pyramid graphs to PDF in C#.NET
- How to use XsPDF Toolkit for .NET to generate Microsoft Polar graphs to PDF page in CSharp .NET
- Drawing Microsoft Line chart to PDF using .NET and XsPDF DLL
- MS Range graphs painted to PDF document - C#.NET online guide


