Make Bar Chart to PDF Sample
insert bar chart to pdf in c# .net

C# code tutorial

PDF Chart PDF Creating & Inserting PDF to Image PDF Digital Signature PDF Extracting PDF Processing & Editing PDF Protecting PDF Barcode

Popular .NET SDK

Create bar charts and graphs in Adobe PDF document.

Bar charts are a great way to maintain performance evaluations, maintain visit frequencies, and show various information. Users can create a bar chart to show comparisons among categories in their data, and save the chart into PDF document to distribut or print.

The .NET PDF Bar Chart control enable devloper to create PDF pages with simple, intuitive, and visually compelling charts for complex statistical or financial analysis. Plot a bar chart with default colors for one or two variables. By default, colors are selected for the bars, background and grid lines, all of which can be customized. What's more, PDF chart text, label, border, axies and legend can all be modified in bar chart designer.

Developers can make a bar chart symbols, and paint in the PDF page using C# .NET PDF bar chart library.

static void AddBarChartToPDF()
    // Create a new PDF document.
    PdfDocument document = new PdfDocument();

    // Create a page.
    PdfPage page = document.AddPage();

    // Generate a 2d bar chart graph
    Chart chart = BarChart();

    // Create a chart frame, set chart location and size
    ChartFrame chartFrame = new ChartFrame();
    chartFrame.Location = new XPoint(30, 30);
    chartFrame.Size = new XSize(500, 600);

    // Render chart symbols into pdf page
    XGraphics g = XGraphics.FromPdfPage(page);

    // Save and show the document           

static Chart BarChart()
    // Set chart type to Bar2D
    Chart chart = new Chart(ChartType.Bar2D);

    // Add first series with name and data
    Series series = chart.SeriesCollection.AddSeries();
    series.Name = "Series 1";
    series.Add(new double[] { 1, 5, -3, 20, 11 });

    // Add second series with name and data
    series = chart.SeriesCollection.AddSeries();
    series.Name = "Series 2";
    series.Add(new double[] { 22, 4, 12, 8, 12 });

    // Add third series with name and data
    series = chart.SeriesCollection.AddSeries();
    series.Name = "Series 3";
    series.Add(new double[] { 12, 14, 2, 18, 1 });

    // Add first fourth with name and data
    series = chart.SeriesCollection.AddSeries();
    series.Name = "Series 4";
    series.Add(new double[] { 17, 13, 10, 9, 15 });

    // Set X axes
    chart.XAxis.MajorTickMark = TickMarkType.Outside;
    chart.XAxis.Title.Caption = "X-Axis";

    // Set Y axes
    chart.YAxis.MajorTickMark = TickMarkType.Outside;
    chart.YAxis.HasMajorGridlines = true;

    // Set plot area (chart diagram)
    chart.PlotArea.LineFormat.Color = XColors.DarkGray;
    chart.PlotArea.LineFormat.Width = 1;
    chart.PlotArea.LineFormat.Visible = true;

    // Set legend
    chart.Legend.Docking = DockingType.Right;

    chart.DataLabel.Type = DataLabelType.Value;
    chart.DataLabel.Position = DataLabelPosition.InsideEnd;

    return chart;

More Excel tutorial