How we Can create column chart in pdf?

PDF column chart is a vertical tetragons used to display information and data. Column chart in the PDF file is similar to bar chart diagram, it's a 2D chart figure.

.NET PDF Column Chart maker can create column chart graphs, and add it to the PDF page with seamless integration. The following online guide shows developers how to create a PDF column chart with data series, x/y Axis, plot area and legend using .NET C# language


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

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

    // Generate a 2d column chart graph
    Chart chart = ColumnChart();

    // 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);
    chartFrame.Add(chart);

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

    // Save and show the document           
    document.Save("ColumnChart.pdf");
    Process.Start("ColumnChart.pdf");
}

static Chart ColumnChart()
{
    // Set chart type to Column2D
    Chart chart = new Chart(ChartType.Column2D);

    // Add first series of column chart 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 of column chart with name and data
    series = chart.SeriesCollection.AddSeries();
    series.Name = "Series 2";
    series.Add(new double[] { 22, 4, 12, 8, 12 });

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

    // Add fourth series of column chart 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.TickLabels.Format = "00";
    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.OutsideEnd;

    return chart;
}

More PDF tutorial