Working with Charts

WorkWithChartDataLabelOfASingleChartSeries

Creating OOXML Charts from Scratch using Aspose.Words

The new insertChart method was added into the DocumentBuilder class. So, let’s see how to insert a simple column chart into the document using DocumentBuilder.insertChart method:

How to insert Column chart

The code produces the following result:

todo:image_alt_text
There are four different overloads for the series Add method, which were exposed to cover all possible variants of data sources for all chart types:

The code produces the following result:

todo:image_alt_text

How to insert Scatter chart

The code produces the following result:

todo:image_alt_text

How to insert Area chart

The code produces the following result:

todo:image_alt_text

How to insert Bubble chart

The code produces the following result:

todo:image_alt_text

Working with Charts through Shape.Chart Object

Once the chart was inserted and filled with data, you are able to change its appearance. Shape.Chart property contains all chart related options available through the public API. For example, let’s change Chart title or legend behavior:

The code generates the followings results:

todo:image_alt_text

How to Work with ChartSeriesCollection of Chart

Let’s look into ChartSeries collection. All chart series are available through the chart.getSeries()collection, which is Iterable:

You can remove series one by one or clear all of them as well as add a new one if needed. The newly inserted chart has some default series added to this collection. To remove them you need to call the chart.getSeries().clear()method.

Working with Single ChartSeries Class

Here is how to work with a particular series.

Please see the result below:

todo:image_alt_text

All single ChartSeries have default ChartDataPoint options, please try using the following code to change them:

todo:image_alt_text

How to Work with Single ChartDataPoint of a ChartSeries

Using ChartDataPoint you are able to customize the formatting of a single data point of the chart series.

Please see the result below:

todo:image_alt_text

How to Work with ChartDataLabel of a Single ChartSeries

Using ChartDataLabel you are able to specify the formatting of a single data label of the chart series, like show/hide LegendKey, CategoryName, SeriesName, Value etc.

Please see the result below:

todo:image_alt_text

How to Define Default Options for ChartDataLabels of ChartSeries

The ChartDataLabelCollection class defines properties which can be used to set default options for ChartDataLabels for Chart Series. These properties include setShowCategoryName, setShowBubbleSize, setShowPercentage, setShowSeriesName, setShowValue etc.

Please see the result below:

todo:image_alt_text

How to Format Number of Chart Data Label

Using the NumberFormat property of ChartDataLabel,  you can specify the number formatting of a single data label of the chart. The below code example shows how to format a number of the data label. 

How to Set Chart Axis Properties

If you want to work with chart axis, scaling, and display units for the value axis, please use ChartAxis, AxisDisplayUnit, and AxisScaling classes. The following code example shows how to define X and Y-axis properties.

How to Set DateTime Value of Axis

The following code example shows how to set date/time values to axis properties.

How to Format Number Value of Axis

The following code example shows how to change the format of numbers on the value axis.

How to Set Bounds of Axis

The AxisBound class represents a minimum or maximum bound of axis values. Bound can be specified as a numeric, date-time or a special “auto” value. The following code example shows how to set the bounds of an axis.

How to Set Interval Unit Between Labels

The following code example shows how to set the interval unit between labels on an axis.

How to Hide Chart Axis

If you want to show or hide the chart axis, you can simply achieve this by setting the value of ChartAxis.Hidden property. The following code example shows how to hide the Y-axis of the chart. 

How to Align Chart Label

If you want to set a text alignment for multi-line labels, you can simply achieve this by setting the value of ChartAxis.setTickLabelAlignment() property. The following code example shows how to tick label alignment.