Chart

The Chart class, a versatile component within the OpenXMLOffice.Presentation library, empowers developers to seamlessly integrate various types of charts into PowerPoint presentations. This class supports multiple chart types and configurations, allowing users to add new charts to a slide or replace existing shapes with dynamic and data-driven visualizations.

List of supported charts
  • Line Chart (2013) :

    • Cluster

    • Stacked

    • 100% Stacked

    • Cluster Marker

    • Stacked Marker

    • 100% Stacked Marker

  • X Y (Scatter) Chart (2013) :

    • Scatter

    • Scatter Smooth Line Marker

    • Scatter Smooth Line

    • Scatter Line Marker

    • Scatter Line

    • Bubble

Basic Code Samples

For each chart family ChartSetting have its releavent options and settings for customization.

public void ChartSample(PowerPoint powerPoint)
{
    // Default Chart Type
    powerPoint.AddSlide(PresentationConstants.SlideLayoutType.BLANK).AddChart(CreateDataCellPayload(), new AreaChartSetting());
    // Customised Chart Type
    powerPoint.GetSlideByIndex(0).AddChart(CreateDataCellPayload(), new AreaChartSetting()
    {
        AreaChartTypes = AreaChartTypes.STACKED
    });
    Slide slide = powerPoint.GetSlideByIndex(1);
    Shape shape = slide.FindShapeByText("shape_id_1");
    shape.ReplaceChart(new Chart(slide, CreateDataCellPayload(),
            new BarChartSetting()
            {
                ChartLegendOptions = new ChartLegendOptions()
                {
                    LegendPosition = ChartLegendOptions.LegendPositionValues.RIGHT
                }
            })
}

ChartSetting Options

PropertyTypeDetails

chartDataSetting

This setting enables users to customize both the input chart data range and value from cell labels with precision.

chartGridLinesOptions

This feature offers crisp options for users to finely customize the gridline settings of the chart.

chartLegendOptions

This feature offers crisp options for users to finely customize the gridline settings of the chart.

height

uint

This parameter precisely determines the height of the entire chart. Default : 6858000

width

uint

This parameter precisely determines the width of the entire chart. Default : 12192000

x

uint

This parameter precisely determines the X position of the entire chart. Default: 0

y

uint

This parameter precisely determines the Y position of the entire chart. Default : 0

ChartDataSetting Options

PropertyTypeDetails

chartDataColumnEnd

uint

Specify the number of columns for chart series; set to 0 for utilizing all columns. Default: 0

chartDataColumnStart

uint

Specify the starting column for chart data. Default: 0

chartDataRowEnd

uint

Specify the number of rows for chart series; set to 0 for utilizing all rows. Default: 0

chartDataRowStart

uint

Specify the starting row for chart data. Default: 0

valueFromColumn

Dictionary<uint, uint>

This option allows configuring a key map where series corresponds to the key, and the value is mapped to a target column based on cell column configuration.

ChartGridLinesOptions Options

PropertyTypeDetails

isMajorCategoryLinesEnabled

bool

Toggle visibility of major category lines with clarity.

isMajorValueLinesEnabled

bool

Toggle visibility of major value lines with clarity.

isMinorCategoryLinesEnabled

bool

Toggle visibility of minor category lines with clarity.

isMinorValueLinesEnabled

bool

Toggle visibility of minor value lines with clarity.

ChartLegendOptions Options

PropertyTypeDetails

isEnableLegend

bool

Toggle visibility of legend with clarity.

isLegendChartOverLap

bool

Activate the option for a sleek and tidy display by allowing the legends to overlap.

isBold

bool

Provide the option to set text in a bold format with clarity.

isItalic

bool

Provide the option to set text in a italic format with clarity.

fontSize

float

Provide the option to set font size with clarity.

fontColor

string?

Optional font color using hex code (without #). Default : Theme Text 1.

underLineValues

UnderLineValues

Text underline options. Default: None

strikeValues

StrikeValues

Text strike options

legendPosition

LegendPositionValues

Legend position in chart. Default: Bottom

ChartDataLabel Options

This is base data label class extended by each chart type to give more specific/relavent options

PropertyTypeDetails

separator

string

Data lable text separator used if multiple label enabled

showCategoryName

bool

Show category name in label

showLegendKey

bool

Show legend key in label

showSeriesName

bool

Show series name in label

showValue

bool

Show value in label

showValueFromColumn

bool

Show value from different column in label

isBold

bool

Set label bold

isItalic

bool

Set label italic

fontSize

float

Set label font size

fontColor

string?

Set label font color

underLineValues

UnderLineValues

Set label underline type

strikeValues

StrikeValues

Set label strike type

ChartAxesOptions Options

This properties give control over the X and Y axes. (Relate placement based on your chart option)

PropertyTypeDetails

invertVerticalAxesOrder

string?

invertHorizontalAxesOrder

string?

isHorizontalAxesEnabled

bool

isHorizontalBold

bool

isHorizontalItalic

bool

horizontalFontSize

float

horizontalFontColor

string?

horizontalUnderLineValues

UnderLineValues

horizontalStrikeValues

StrikeValues

isVerticalBold

bool

isVerticalItalic

bool

verticalFontSize

float

verticalFontColor

string?

verticalUnderLineValues

UnderLineValues

verticalStrikeValues

StrikeValues

isVerticalAxesEnabled

bool

ChartSeriesSetting Options

PropertyTypeDetails

borderColor

string?

Explicit border color for current data series

ChartDataPointSettings Options

PropertyTypeDetails

fillColor

string?

Explicit fill color for one specific data point in a series

borderColor

string?

Explicit border color for one specific data point in a series

Embedded Excel Component

Embedded excel can be accessed using GetChartWorkBook return OpenXMLOffice.Excel Worksheet. Refer Worksheet section for more details

Chart chart = powerPoint.AddSlide(PresentationConstants.SlideLayoutType.BLANK)
				.AddChart(CreateDataCellPayload(), new G.LineChartSetting());
Worksheet worksheet = chart.GetChartWorksheet();
worksheet.SetRow(12, 1, new DataCell[] { 
new() {
  cellValue = "Added Additional Data To Chart",
  dataType = CellDataType.STRING
  }
}, new());

Last updated