A newer version of this page is available. Switch to the current version.

How to: Protect a Chart

  • 2 minutes to read

After you create a chart, you can apply chart protection to prevent your chart from being modified by a user. To protect a chart, utilize the ChartOptions.Protection property. After chart protection is specified, the chart becomes completely locked, so that an end-user cannot select the chart, modify its elements or change chart data references.

You can also protect the entire worksheet where the chart is located by using the Worksheet.Protect method. For detailed information on the protection functionality in the SpreadsheetControl, refer to the Protection article.

The following example demonstrates how to create a clustered column chart and apply chart protection using the ChartOptions.Protection property.

Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:D4"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];

// Specify the chart style.
chart.Style = ChartStyle.ColorDark;

// Apply the chart protection.
chart.Options.Protection = ChartProtection.All;
See Also