Skip to main content

How to Create a Shortcut Visualization

Shortcut visualizations, or configured visualizations, are base visualizations where the data dependent properties have been configured.

Overview

This topic describes how to create a shortcut visualization for Spotfire. It contains implementation details on how to turn a bar chart into a histogram.

Histogram
Background Information
  • Creating a Visualization
    A visualization is a visual displaying data in Spotfire. A custom visualization defines a unique visualization, implementing model, view, and possibly using additional components.
Prerequisites
  • Spotfire SDK\Examples\Extensions\SpotfireDeveloper.CustomVisualsExample
    The project contains the code of several visualizations. One is the SpotfireDeveloper.ConfiguredBarChart shortcut visualization.

Turning a bar chart into a histogram

Open the SpotfireDeveloper.CustomVisualsExample.csproj SDK project in Visual Studio®.

ConfiguredBarChartFactory.cs

The purpose of the ConfiguredBarChart shortcut visualization in the SDK is to configure a bar bar chart to behave as a histogram. Still, a new visual must be registered in an add-in to make the shortcut visualization available in Spotfire:

public sealed class CustomVisualsAddIn : AddIn { // Registers the custom visuals in the add-in. protected override void RegisterVisuals(AddIn.VisualRegistrar registrar) { base.RegisterVisuals(registrar); registrar.Register(new ConfiguredBarChartFactory()); } }

CustomVisualsIdentifiers.cs

The CustomVisualsIdentifiers contains type identifiers for the custom visuals. Add a type identifier for the configured bar chart:

public sealed class CustomVisualsIdentifiers : CustomTypeIdentifiers { // Type identifier for the configured Bar Chart. public static readonly CustomTypeIdentifier ConfiguredBarChart = CreateTypeIdentifier( "SpotfireDeveloper.ConfiguredBarChart", Properties.Resources.ConfiguredBarChartDisplayName, Properties.Resources.ConfiguredBarChartDescription); }

ConfiguredBarChartFactory.cs

A shortcut visualization inherits from the ConfiguredVisualFactory base class passing the visualization type as parameter. A number of parameters must be specified in a call to the base class: The visualization that the configured visualization is based on, the visual category, associated GUI icon, and associated licenses. The icon is a bitmap used to identify the configured bar chart in the Spotfire application menus. Include it in the .NET environment resources.

internal sealed class ConfiguredBarChartFactory : ConfiguredVisualFactory<BarChart> { internal ConfiguredBarChartFactory() : base( VisualTypeIdentifiers.BarChart, // Type identifier for base visualization CustomVisualsIdentifiers.ConfiguredBarChart, // New Type identifier VisualCategory.Visualization, // Visual category Properties.Resources.ConfiguredBarChartImage, // Icon null) // License { // Empty } }

To configure data dependent properties, override the AutoConfigureCore method. First Data.Autoconfigure is used for the default data setup. Then the individual settings are configured to make the bar chart behave like a histogram:

protected override void AutoConfigureCore(BarChart visual) { base.AutoConfigureCore(visual); // Set default data table, filterings and marking visual.Data.AutoConfigure(); visual.BarWidth = 100; visual.YAxis.Expression = "Count()"; visual.ShowShadowBars = true; if (visual.Data.DataTableReference != null) { foreach (DataColumn column in visual.Data.DataTableReference.Columns) { // Find a numeric column if (column.Properties.DataType.IsNumeric) { visual.XAxis.Expression = "BinByEvenIntervals(" + column.NameEscapedForExpression + ", 20)"; break; } } } }