Spread.NET 13 WinForms introduces a new feature that can define a custom function visualizer that draws a custom data visualization in the cell and/or applies a format to the cell. This feature is similar to custom sparklines, but easier to implement using the new Calculation Engine to accept the custom function arguments.
The following topics are covered in this blog:
- Creating a Data Visualization Function
- Using a Data Visualization Function
- Creating a QR Code Data Visualization Function
- Applying a Format
- Samples
Creating a Data Visualization Function
To use this feature, you must implement a custom data visualizer class which inherits from GrapeCity.Spreadsheet.FunctionVisualizer.
QRCodeFunctionVisualizer
The code above shows how the FunctionVisualizer can access the VisualizationData passed into the function for cellValue and use the EvaluationContext from the CalculationEngine to fetch the function arguments from the VisualizationData.Parameter.
The following code applies the QRCodeFunctionVisualizer to the FpSpread control on the form:
Form_Load
The result shows the QR code in cell A1:
Figure 1: QRCodeFunctionVisualizer in action
Applying a Format
A VisualFunction can apply a format to the cell instead of drawing a visualization. The next example shows a custom FunctionVisualizer which can do both:
CustomFunctionVisualizer
The CustomFunctionVisualizer above can operate as either visual and draw a custom data visualization in the cell, or nonvisual and instead apply a yellow fill when the cell value is a CalcError.
The CustomFuctionVisualizer is used with this custom SUMVisualFunction:
SUMVisualFunction
The following code in the -Form_Load_ event initializes the custom SUMVisualFunction:
Form_Load
The cells C3 and D4 show the SUM1 and SUM2 functions evaluating, with the first showing a visualization and the second one showing a style:
Figure 2: SUMVisualFunction in action
Note that the cell style applied to C3 does not show, since the custom visual function returns False for IsShowCell. When the cell is edited, then the style shows while editing the formula:
Figure 3: Cell style shows while editing visual function cell
When an error value is typed in cell A1, then the visual function cells update:
Figure 4: Error values showing custom data visualization and style
Samples
The sample code for the QR code visualizer is included in the v13 control explorer demo that is included in the trial download.
If you have any questions about this tutorial, please them them in the comment thread below.