In some cases (for ex. Trellis view), to get more visualization space, we could simply hide the legend.
For this, on change of View Type (using a drop down property control – ViewType), I am invoking a script to show or hide the legend.
Below, creating the property control ViewType:
IronPython Code: from Spotfire.Dxp.Application import Visuals from Spotfire.Dxp.Application.Visuals import LineChart from Spotfire.Dxp.Application.Visuals import Legend for vis in Application.Document.ActivePageReference.Visuals: if vis.Title == "Sales - Trellis View": vis.As[LineChart]().Legend.Visible = False if vis.Title == "Sales - Full View": vis.As[LineChart]().Legend.Visible = True
The Straight Line Fit from Lines & Curves could be customized and shown/hidden as per requirement.
Below is a Scatter plot used to add a straight line fit.
Make sure that the Straight Line Fit is the first fitting model in Lines & Curves (to use the script below).
Add a button with script as below. In the previous step, since the first fitting model is our Straight Line Fit, we refer it in the script as FittingModels. If your Straight Line is the second fitting model, you could refer it as FittingModels and so on. Additionally, we need to pass the Scatter Plot as Visualization input vis to the script.
IronPython Script: from Spotfire.Dxp.Application.Visuals import ScatterPlot for fm in vis.As[ScatterPlot]().FittingModels: for vis in Application.Document.ActivePageReference.Visuals: if vis.Title == "Sales by Profit": if vis.As[ScatterPlot]().FittingModels.Enabled == True: vis.As[ScatterPlot]().FittingModels.Enabled = False else: vis.As[ScatterPlot]().FittingModels.Enabled = True
Now you can use the button to toggle and show/hide the regression line.
When using multiple date columns (switched using property control) on a particular axis, we lose the ability to change the time dimension of the date selected. In order to overcome this issue, we can add a Time Hierarchy property control (a slider) and use it to alter the date column’s time hierarchy.
We start off by building a property control for changing date column. An important note here is to provide the Value as exact literals of the column name which you want to use against a Display Name.
Then we create a TimeHierarchy slider control to navigate across three dimensions – Year, Quarter and Month.
And apply the below custom expression on the date column.
This customization allows us to change the Time Hierarchy for Date columns. Below is a view of quarterly Sales (by Order Date)
And a monthly Sales view (using Dispatch Date)
To perform K-Means clustering in Spotfire, we need an appropriate line chart on which the clustering calculation could be performed.
Below we are using a simple line chart with Sales on Y-axis (a single column and not a custom expression with multiple columns) and Order Date on X-axis.
The Euclidean distance is used to perform the clustering with maximum number of clusters to be 9.
Here is a segmented view of similar product sub-categories which fall in clusters depending on their sales performance.
References (apart from those included as part of plot titles):
Reference snippet to pass a radio button value into Spotfire context, that is into a Document Property.
<FORM><B>Select date for filtering:</B>
value=”N” CHECKED type=radio name=pack1>
value=”Y” type=radio name=pack1>Date 2