Quickstart
Quickstart
This page contains two self-contained examples you can copy into a .NET console project (after building the library from source) and run immediately.
Example 1 — Create a Document with a Line Chart
Create a new document, insert a line chart with DocumentBuilder.InsertChart(), clear the
default series, and add your own data:
using Aspose.Words;
using Aspose.Words.Drawing.Charts;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertChart(ChartType.Line, 432, 252);
Chart chart = shape.Chart;
// Delete default generated series.
chart.Series.Clear();
string[] categories = new string[] { "AW Category 1", "AW Category 2", "AW Category 3" };
chart.Series.Add("AW Series 1", categories, new double[] { 4.3, 2.5, 3.5 });
doc.Save("chart.docx");Example 2 — Configure a Pie Chart with Data Labels
Insert a pie chart, add a series, and configure ChartDataLabelCollection to show percentages
and values:
using Aspose.Words;
using Aspose.Words.Drawing.Charts;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertChart(ChartType.Pie, 432, 252);
Chart chart = shape.Chart;
chart.Series.Clear();
ChartSeries series = chart.Series.Add("Series 1",
new string[] { "Category1", "Category2", "Category3" },
new double[] { 2.7, 3.2, 0.8 });
ChartDataLabelCollection labels = series.DataLabels;
labels.ShowPercentage = true;
labels.ShowValue = true;
labels.ShowLeaderLines = false;
labels.Separator = " - ";
doc.Save("pie-chart.docx");ChartSeries.Add() accepts category names alongside the values, and ChartDataLabelCollection
controls what each data label displays — percentage, value, category name, or a combination
separated by Separator.
Next Steps
- Installation Guide — Build from source and reference the library
- Features and Functionalities — Full feature reference with examples
- Developer Guide — Document creation, editing, and chart APIs