How to: Protect a Chart
- 2 min 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 a user cannot select the chart, modify its elements or change chart data references.
The following example demonstrates how to create a clustered column chart and apply chart protection using the ChartOptions.Protection property.
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-chart-api-t132724
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;