Intersoft ClientUI Documentation
How-to: Extending SqlReportViewer Rendering Engine

The following example shows how to extend SqlReportViewer rendering engine to display chart elements.

Example

Description

SqlReportViewer provides extensibility features to render data visualization items in SQL Reporting Services such as Chart, Gauge, Map and Sparkline. This topic shows how to extend SqlReportViewer to render the Chart elements using the Chart control from Silverlight Toolkit.

Code

Extending XamlRenderer

First, create a new class that derives from the XamlRenderer class.

View
Copy Code
public class CustomXamlRenderer : XamlRenderer

Next, set the required namespace for the XAML page, in this case, set the namespace to the Silverlight Toolkit assembly.

View
Copy Code
public override string CustomNamespace
{
        get
        {
                string customNamespace = "";
                customNamespace += string.Format("xmlns:Charting=\"{0}\" ",
                        "clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit");
                customNamespace += string.Format("xmlns:DataVis=\"{0}\" ",
                        "clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit");
                customNamespace += string.Format("xmlns:ChartingPrimitives=\"{0}\" ",
                        "clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit");

                return customNamespace;
        }
}

Finally, set the chart render instance to the new custom ChartRenderer class.

View
Copy Code
public override ChartRenderer ChartRenderInstance
{
        get
        {
                if (this._customChartRenderInstance == null)
                        this._customChartRenderInstance = new CustomChartRenderer(this.ToggleControlItem,
                                this.ToggleControlRelation);
                return this._customChartRenderInstance;
        }
}

Extending ChartRenderer

Once you extended the XamlRendered, the next step is to create a custom chart rendered that derives from the ChartRenderer class

View
Copy Code
public class CustomChartRenderer : ChartRenderer

Override both RenderItem definition.

RenderItem(Chart chart, ReportRenderItem reportRenderItem) function is used in rendering chart in the page. The base function needs to be called in order to assign the correct size and position of the chart container in the page. In the final step, set the reportRenderItem.ItemMetadata.XamlContent with the processed chart XAML string.

View
Copy Code
public override void RenderItem(Chart chart, ReportRenderItem reportRenderItem)
{
        base.RenderItem(chart, reportRenderItem);

        ...

        reportRenderItem.ItemMetadata.XamlContent = ...
}

RenderItem(Chart chart, out string customAttribute) is invoked when rendering chart inside a tablix. CustomAttribute parameter could be assigned in order to add attribute to the chart's cell container. In the final step, set the processed chart XAML string as return value.

View
Copy Code
public override string RenderItem(Chart chart, out string customAttribute)
{
        customAttribute = "";
        
        ...
        
        return ...
}

In order to extend the Map and Gauge rendering engine, please implement with the similar steps.

See Also

Concepts