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

ChartDataSetting Options

ChartGridLinesOptions Options

ChartLegendOptions Options

ChartDataLabel Options

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

ChartAxesOptions Options

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

ChartSeriesSetting Options

ChartDataPointSettings Options

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