Search Results for

    Show / Hide Table of Contents

    Charts

    Version 6.1.0

    In this article

    • Introduction

    This article describes how charts are added to a MigraDoc document.

    Introduction

    With MigraDoc you can add charts you automatically generate from given data to your document. There are a lot of possibilities to display this data. Here is an example of a generated pie chart:

    // Add a chart.
    var chart = section.AddChart(ChartType.Pie2D);
    
    // Format the border and size.
    chart.LineFormat.Color = Colors.DarkGray;
    chart.LineFormat.Width = Unit.FromPoint(1);
    chart.Width = Unit.FromCentimeter(16);
    chart.Height = Unit.FromCentimeter(12);
    
    // Add a padding around the pie.
    chart.PlotArea.TopPadding = Unit.FromCentimeter(1);
    chart.PlotArea.RightPadding = Unit.FromCentimeter(1);
    chart.PlotArea.BottomPadding = Unit.FromCentimeter(1);
    chart.PlotArea.LeftPadding = Unit.FromCentimeter(1);
    
    // Add a series and format it.
    var series = chart.SeriesCollection.AddSeries();
    series.HasDataLabel = true;
    series.DataLabel.Position = DataLabelPosition.Center;
    series.DataLabel.Font.Size = Unit.FromPoint(12);
    series.DataLabel.Font.Bold = true;
    series.LineFormat.Color = Color.FromRgb(96, 96, 96);
    
    // Add some data and format it.
    var point = series.Add(32);
    point.FillFormat.Color = Colors.MediumOrchid;
    
    point = series.Add(20);
    point.FillFormat.Color = Colors.DodgerBlue;
    
    point = series.Add(11);
    point.FillFormat.Color = Colors.Chocolate;
    
    point = series.Add(7);
    point.FillFormat.Color = Colors.LimeGreen;
    
    // Add the names for the data.
    var xSeries = chart.XValues.AddXSeries();
    xSeries.Add("Value 1", "Value 2", "Value 3", "Value 4");
    
    // Add and format the legend.
    var legend = chart.RightArea.AddLegend();
    legend.LineFormat.Color = Colors.DarkGray;
    legend.LineFormat.Width = Unit.FromPoint(1);
    

    See full Example in PDFsharp.Sample repository. Show resulting PDF

    Width, Height, Size and the padding properties are of the type Unit (see Formats / Unit for more information).

    Color is a property of the type Color (see Formats / Colors for more information).

    You can find another example of a generated chart inside the HelloMigraDoc sample explained in Topics / Start / HelloMigraDoc. Some more examples can also be found in Grammar by Example (GBE) (see MigraDoc Overview / Grammar by Example for more information). In Grammar by Example the samples are written in MigraDoc Document Description Language (MDDDL), but you can mostly deduce the required code from it.

    • Edit this page
    In this article
    Generated by DocFX  |   Privacy policy  |   Legal notice
    Back to top