Skip to content

This content is for v1.x (Discontinued). Switch to the Stable version.

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 chart.

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

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

ChartSetting<G.PresentationSetting> Options

Section titled “ChartSetting<G.PresentationSetting> Options”
PropertyTypeDetails
hyperlinkPropertiesHyperlinkPropertiesHyperlink properties for the entire chart
isSecondbool

If combo chart this can be used to indicate secondary axis activation.

chartDataSettingChartDataSetting

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

chartGridLinesOptionsChartGridLinesOptions

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

chartLegendOptionsChartLegendOptions

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

applicationSpecificSetting<ApplicationSpecificSetting>

This is generic class setting. For Presentation it is PresentationSetting

PropertyTypeDetails
heightuint

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

widthuint

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

xuint

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

yuint

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

PropertyTypeDetails
chartDataColumnEnduint

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

chartDataColumnStartuintSpecify the starting column for chart data.
Default: 0
chartDataRowEnduint

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

chartDataRowStartuintSpecify the starting row for chart data.
Default: 0
advancedDataLabelAdvancedDataLabelUsed for Data Label Option From Office 2013
PropertyTypeDetails
isMajorCategoryLinesEnabledboolToggle visibility of major category lines with clarity.
isMajorValueLinesEnabledboolToggle visibility of major value lines with clarity.
isMinorCategoryLinesEnabledboolToggle visibility of minor category lines with clarity.
isMinorValueLinesEnabledboolToggle visibility of minor value lines with clarity.
PropertyTypeDetails
isEnableLegendboolToggle visibility of legend with clarity.
isLegendChartOverLapbool

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

isBoldboolProvide the option to set text in a bold format with clarity.
isItalicboolProvide the option to set text in a italic format with clarity.
fontSizefloatProvide the option to set font size with clarity.
fontColorstring?

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

underLineValuesUnderLineValuesText underline options. Default: None
strikeValuesStrikeValuesText strike options
legendPositionLegendPositionValuesLegend position in chart. Default: Bottom

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

PropertyTypeDetails
separatorstringData label text separator used if multiple label enabled
showCategoryNameboolShow category name in label
showLegendKeyboolShow legend key in label
showSeriesNameboolShow series name in label
showValueboolShow value in label
isBoldboolSet label bold
isItalicboolSet label italic
fontSizefloatSet label font size
fontColorstring?Set label font color
underLineValuesUnderLineValuesSet label underline type
strikeValuesStrikeValuesSet label strike type
PropertyTypeDetails
showValueFromColumnboolShow Advanced data label
valueFromColumnDictionary<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.

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

PropertyTypeDetails
invertVerticalAxesOrderstring?
invertHorizontalAxesOrderstring?
isHorizontalAxesEnabledbool
isHorizontalBoldbool
isHorizontalItalicbool
horizontalFontSizefloat
horizontalFontColorstring?
horizontalUnderLineValuesUnderLineValues
horizontalStrikeValuesStrikeValues
isVerticalBoldbool
isVerticalItalicbool
verticalFontSizefloat
verticalFontColorstring?
verticalUnderLineValuesUnderLineValues
verticalStrikeValuesStrikeValues
isVerticalAxesEnabledbool
PropertyTypeDetails
borderColorstring?Explicit border color for current data series
PropertyTypeDetails
fillColorstring?Explicit fill color for one specific data point in a series
borderColorstring?Explicit border color for one specific data point in a series

Embedded excel can be accessed using GetWorkBookStream return OpenXMLOffice.Spreadsheet Worksheet. Refer Worksheet section for more details

Chart chart = powerPoint.AddSlide(PresentationConstants.SlideLayoutType.BLANK)
.AddChart(CreateDataCellPayload(), new G.LineChartSetting());
using Stream stream = chart.GetWorkBookStream();
// Creating a new excel instance object from chart base source
// Note: Updating data directly in Excel will now reflect in PPT Chart graphic cache on open.
// Use Chart object data for embedding chart data and this handle for extending addition of data,logo,etc...
X.Excel excel = new(stream);
Worksheet worksheet = excel.GetWorkSheet("Sheet1");
worksheet.SetRow(12, 1, new DataCell[] {
new() {
cellValue = "Added Additional Data To Chart",
dataType = CellDataType.STRING
}
}, new());
// Save Content after completion to the source stream
// Important OpenXML-Office components work with memory the source file/stream will not get replaced automatically
// You can save to same source to overwrite it or make a duplicate copy without disturbing the source
excel.SaveAs(chart.GetWorkBookStream());