This C#.NET guide demonstrates how to generate the Microsoft 100% Stacked Area Chart (both 2D and 3D 100% Stacked Area Chart), and insert the MS 100% Stacked Area Chart image to PDF document.
Area stacked-100 chart can be modified in variety parameters, such as size, color, location and rotation. The following C# sample code shows how to create and insert Microsoft Stacked 100% Area Chart to PDF document programmatically.
Please note, before developers using the chart creating code, the MS Chart Control should be referred to your .NET program:
- System.Windows.Forms.DataVisualization.Charting (for .NET WinForms project)
- System.Web.UI.DataVisualization.Charting (for ASP.NET application)
Make and paint Microsoft 2D 100% Stacked Area 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 stacked 100 area chart stream object Stream chartStream = CreateMSStacked100AreaChart(); // 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("MSStacked100AreaChart.pdf"); Process.Start("MSStacked100AreaChart.pdf"); } public static Stream CreateMSStacked100AreaChart() { // Create ms chart object Chart chart = new Chart(); ChartArea chartArea = new ChartArea(); Series series1 = new Series(); Series series2 = new Series(); Series series3 = new Series(); // Input Data Point DataPoint dataPoint1 = new DataPoint(0, 5); DataPoint dataPoint2 = new DataPoint(0, 8.5); DataPoint dataPoint3 = new DataPoint(0, 9); DataPoint dataPoint4 = new DataPoint(0, 7); DataPoint dataPoint5 = new DataPoint(0, 5); DataPoint dataPoint6 = new DataPoint(0, 5); DataPoint dataPoint7 = new DataPoint(0, 4); DataPoint dataPoint8 = new DataPoint(0, 5); DataPoint dataPoint9 = new DataPoint(0, 3.5); DataPoint dataPoint10 = new DataPoint(0, 4); DataPoint dataPoint11 = new DataPoint(0, 3); DataPoint dataPoint12 = new DataPoint(0, 7); DataPoint dataPoint13 = new DataPoint(0, 2); DataPoint dataPoint14 = new DataPoint(0, 4); DataPoint dataPoint15 = new DataPoint(0, 8); // Set series1 with data, color, chart type and name series1.BorderColor = Color.FromArgb(180, 26, 59, 105); series1.ChartType = SeriesChartType.StackedArea100; series1.Color = Color.FromArgb(220, 65, 140, 240); series1.Name = "Series1"; series1.Points.Add(dataPoint1); series1.Points.Add(dataPoint2); series1.Points.Add(dataPoint3); series1.Points.Add(dataPoint4); series1.Points.Add(dataPoint5); // Set series2 with data, color, chart type and name series2.BorderColor = Color.FromArgb(180, 26, 59, 105); series2.ChartType = SeriesChartType.StackedArea100; series2.Color = Color.FromArgb(220, 252, 180, 65); series2.Name = "Series2"; series2.Points.Add(dataPoint6); series2.Points.Add(dataPoint7); series2.Points.Add(dataPoint8); series2.Points.Add(dataPoint9); series2.Points.Add(dataPoint10); // Set series3 with data, color, chart type and name series3.BorderColor = Color.FromArgb(180, 26, 59, 105); series3.ChartType = SeriesChartType.StackedArea100; series3.Color = Color.FromArgb(220, 224, 64, 10); series3.Name = "Series3"; series3.Points.Add(dataPoint11); series3.Points.Add(dataPoint12); series3.Points.Add(dataPoint13); series3.Points.Add(dataPoint14); series3.Points.Add(dataPoint15); // Bind series data to chart chart.Series.Add(series1); chart.Series.Add(series2); chart.Series.Add(series3); // 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; }
Create and insert MS 3D 100% Stacked Area Chart to PDF in C# code.
All the step and code are the same as above, only need change one line code chartArea.Area3DStyle.Enable3D = false; in the "CreateMSStacked100AreaChart()" 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
- CSharp .NET online tutorial for generation Microsoft Spline Range graphing to PDF file
- Paint MS Range graphing to PDF in .NET C#
- Microsoft Point chart creating to PDF in .NET Visual C# is quite easy and quick using XsPDF Control for .NET
- How to create Microsoft Bar graphs to PDF document in ASP.NET program using Visual Studio .NET framework
- How to create Microsoft 100% Stacked Bar chart to PDF document in ASP.NET MVC using C#
- How to use XsPDF Control for .NET to save Microsoft Area graphing to PDF page in CSharp .NET
- Converting Microsoft Line graphing to PDF using .NET and XsPDF source code
- MS Column graphs inserting to PDF in C#.NET is quite easy and quick using XsPDF Control for .NET
- Painting MS Polar diagram to PDF using C# and XsPDF source code
- How to use XsPDF DLL for .NET to add MS Range Bar diagram to PDF page in .NET C#
- Draw Microsoft Stacked Column graphs to PDF in .NET Visual C#
- How to use XsPDF SDK for .NET to draw MS Pyramid diagram to PDF page in C#
- How to use XsPDF source code for .NET to paint Microsoft Spline Area chart to PDF page in Visual C#
- Microsoft Doughnut chart adding to PDF in Visual Studio .NET framework is quite easy and quick using XsPDF Component for .NET
- Visual C# online sample for exporting Microsoft 100% Stacked Column graphs to PDF file