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

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

    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

    // 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