Jump to content
  • Create a Shortcut Visualization in Spotfire®


    Introduction

    Shortcut visualizations, or configured visualizations, are base visualizations where the data dependent properties have been configured. Since the Spotfire built-in visualization can be configured in numerous ways through the API, creating a shortcut visualization may in some cases be a more convenient way to add a new visualization type, compared to creating a custom visualization.

    See also Create Extensions to Spotfire for an overview of the different extension types available.

    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.png.2f2ef2fb6a0113beac9328e82d727052.png

    Prerequisites

    The Spotfire SDK is required when doing .NET extensions to the Spotfire platform. It is available in the Spotfire Developer software which is available for download here.

    The Visual Studio project "Spotfire SDK\Examples\Extensions\SpotfireDeveloper.CustomVisualsExample" contains the code of several visualizations. One is the SpotfireDeveloper.ConfiguredBarChart shortcut visualization described in this article.

    Implementation

    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;
            }
         }
       }
    }
     

    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());
        }
    }
     

    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);
    }
     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...