How to Customize a Chart in Blazor Spreadsheet
19 Nov 20266 minutes to read
Once a chart is inserted into the worksheet, you can customize its appearance and structure from the Chart Design tab in the ribbon.
Move a Chart
To reposition a chart within the worksheet:
- Click the chart to select it (selection handles appear around it).
- Click and drag the chart to your desired location.
- Release to place the chart in the new position.
Resize a Chart
To adjust the chart size:
- Click the chart to select it.
- Drag a middle edge handle to resize along a single axis — horizontally or vertically.
- Release to apply the new size.
Access Chart Design Options
When a chart is selected, a Chart Design tab becomes available in the ribbon. This tab provides tools to modify chart elements and structure.
Add or Modify Chart Elements
Using the Add Chart Element option, you can enhance your chart with the following elements:
Axes and Axis Titles
- Purpose — Clearly describe what your data values represent.
- When to use — Add when axis measurements are not immediately obvious.
- How to add — Chart Design tab → Add Chart Element → Axes → Select the desired axis type.
Chart Title
- Purpose — Explain what the chart represents at a glance.
- When to use — Always recommended for clarity.
- How to add — Chart Design tab → Add Chart Element → Chart Title → Choose a title style.
Data Labels
- Purpose — Display exact values directly on the chart.
- When to use — Helpful when precise values are important to viewers.
- How to add — Chart Design tab → Add Chart Element → Data Labels → Select label position.
Gridlines
- Purpose — Improve readability by providing a reference grid.
- When to use — Useful for charts with many data points.
- How to add — Chart Design tab → Add Chart Element → Gridlines → Select gridline type.
Legends
- Purpose — Identify and distinguish data series in multi-series charts.
- When to use — Essential when multiple data series are plotted.
- How to add — Chart Design tab → Add Chart Element → Legend → Choose legend position.
Switch Data Orientation
If your chart is not displaying data as intended, you can reverse how rows and columns are interpreted:
- Select the chart by clicking on it.
- Go to Chart Design tab in the ribbon.
- Click Switch Row/Column to flip the data orientation.
- Review the result — The chart now groups data differently.
This is useful when:
- You want to compare categories differently.
- Your data is organized differently than expected.
- You need to highlight different trends or patterns.
When inserting a chart programmatically, the equivalent option is the IsSeriesInRows property of the ChartModel (passed to the InsertChartAsync method).
Change Chart Type
To switch between chart types after creation:
- Select the chart by clicking on it.
- Go to Chart Design tab in the ribbon.
- Click Chart Type option.
- Select a new type (Column, Bar, Line, Area, Pie, etc.).
Update Chart Programmatically
The UpdateChartAsync() method asynchronously updates the properties of an existing chart identified by ChartOptions.Id. This allows you to modify an existing chart without recreating it.
Only the properties provided in the ChartOptions object are applied. Any property that is not specified, or is set to null, retains its current value.
Chart update options
The UpdateChartAsync() method can update chart settings such as chart type, data range, title, legend, theme, data labels, color palette, and other supported chart properties.
| Property | Description |
|---|---|
Id |
Specifies the chart identifier to update. |
ChartType |
Changes the chart type. |
ChartTitle |
Updates the chart title. |
Range |
Updates the chart data range. |
Theme |
Applies a chart theme. |
ShowPrimaryVerticalAxis |
Controls the primary vertical axis visibility. |
PrimaryVerticalAxisTitle |
Updates the primary vertical axis title. |
ColorPalette |
Updates the chart color palette. |
Only the properties included in the
ChartOptionsinstance are applied during the update.
Code Example
@page "/"
@using Syncfusion.Blazor.Spreadsheet
@using Syncfusion.Blazor.Buttons
<SfButton OnClick="UpdateSalesChart">Update Chart</SfButton>
<SfSpreadsheet @ref="SpreadsheetInstance">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
public SfSpreadsheet SpreadsheetInstance { get; set; }
private async Task UpdateSalesChart()
{
var chartOptions = new ChartOptions
{
Id = "SalesChart",
ChartType = ChartType.Line,
ChartTitle = "Updated Sales Report",
Theme = Theme.Fabric,
Range = "Sheet1!A1:C10",
ShowPrimaryVerticalAxis = true,
PrimaryVerticalAxisTitle = "Sales Amount",
ColorPalette = new[] { "#FF5733", "#33FF57" }
};
await SpreadsheetInstance.UpdateChartAsync(chartOptions);
}
}Customization of line chart markers
You can listen to the ActionBeginning event to detect when a chart operation starts and react to it in code. Within the handler you receive an ActionBeginningEventArgs that exposes the action name and lets you cancel the operation.
@page "/"
@using Syncfusion.Blazor.Spreadsheet
<SfSpreadsheet ActionBeginning="OnActionBeginning">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
private void OnActionBeginning(ActionBeginningEventArgs args)
{
// React to chart-related actions (e.g. switch row/column, change chart type)
if (args.Action == "Chart")
{
// Hook point for additional chart logic. Marker customization for line
// charts is not yet exposed on the Blazor ChartModel.
}
}
}The Blazor
ChartModelexposesId,ChartType,Range,Theme, andIsSeriesInRows. Marker shape, size, fill color, and border customization that exists in the ReactactionBeginmarker override is not currently exposed on the BlazorChartModel. Use the Chart Design ribbon options to modify chart elements until an API equivalent is available.