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
  • Area Chart (2007) :

    • Cluster

    • Stacked

    • 100% Stacked

    • Cluster 3D

    • Stacket 3D

    • 100% Stacked 3D

  • Bar Chart (2007) :

    • Cluster

    • Stacked

    • 100% Stacked

    • Cluster 3D

    • Stacket 3D

    • 100% Stacked 3D

  • Column Chart (2007) :

    • Cluster

    • Stacked

    • 100% Stacked

    • Cluster 3D

    • Stacket 3D

    • 100% Stacked 3D

  • Line Chart (2007) :

    • Cluster

    • Stacked

    • 100% Stacked

    • Cluster Marker

    • Stacked Marker

    • 100% Stacked Marker

  • X Y (Scatter) Chart (2007) :

    • Scatter

    • Scatter Smooth Line Marker

    • Scatter Smooth Line

    • Scatter Line Marker

    • Scatter Line

    • Bubble

    • Bubble 3D

Basic Code Samples

For each chart family ChartSetting have its releavent 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>());
    // Customised 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

PresentationSetting 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

AdvancedDataLabel Options (2013)

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 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());

Last updated