I am trying to program a simple IronPython script to set the date range of my line graph x-axis in Spotfire based on property control user inputs. I cannot find any documentation or examples of this, so here's what I guessed, but it's not working:
from Spotfire.Dxp.Application.Visuals import LineChart
from Spotfire.Dxp.Application.Visuals import ScaleAxis
plot1= plot1.As[LineChart]()
plot1.XAxis.Min = StartDate
plot1.XAxis.Max = EndDate
I entered the visualization and the property control as Script Parameters in the Edit Script window. Does anyone know how to make this work?? Thanks!
Note: I do not want to use zoom sliders.
Update: I am doing a Sum([Column]) OVER (AllPrevious([Date])) so I can't filter any dates out for the calculation of Y. I just need them filtered out of the X axis range. The original table is structured like this: | Product | Date | Phase |
And I have calculated columns for each of the phases with formulas: If([Phase]="Phase A",1,0)
Essentially the graph shows how many products have gone through each stage of production over time, so I need to always know the completion date of each phase to count the number of products in that phase on any particular date. I only want to see a certain date range on the X-axis though because I have some other graphs placed above/below from 2 other tables to compare sales and costs, and it's easier to analyze based on the number of products in each phase when the axes show the same dates. Sorry I can't upload pictures so I hope that makes sense.
We only care about the most recent sales/costs, and I restrict those dates with the filters using Data on Demand for the sales and costs tables so the graphs automatically show what I want. Now the only issue is filtering the range for the # of Products graph because the dates in the phase columns can go back years, and we need to know how many total products are in each phase, but we don't want to see the graph from the beginning of time...I can achieve this with a zoom slider or hardcoding the min/max in that graph, but I was really hoping for something automated so we don't have to continually adjust it.
I found an automated solution, and you can either set it to use zoom sliders or not. You have to input the StartDate and EndDate properties as Script parameters, and you also have to enter every visualization as a Script parameter (so I needed 5 total for my script). The code is posted below - hope this helps someone!
NO ZOOM SLIDERS:
#Import the necessary namespaces
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals import AxisRange
from Spotfire.Dxp.Data import DataPropertyClass
#Define variables
min = Document.Properties["StartDate"]
max = Document.Properties["EndDate"]
#Cast visual as specific plot type
#Note use of VisualContent for any chart type
plot1= plot1.As[VisualContent]()
plot2= plot2.As[VisualContent]()
plot3= plot3.As[VisualContent]()
#Set visualization parameters
plot1.XAxis.Range = AxisRange(min,max);
plot2.XAxis.Range = AxisRange(min,max);
plot3.XAxis.Range = AxisRange(min,max);
WITH ZOOM SLIDERS:
#Import the necessary namespaces
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals import AxisRange
from Spotfire.Dxp.Data import DataPropertyClass
#Define variables
min = Document.Properties["StartDate"]
max = Document.Properties["EndDate"]
#Cast visual as specific plot type
#Note use of VisualContent for any chart type
plot1= plot1.As[VisualContent]()
plot2= plot2.As[VisualContent]()
plot3= plot3.As[VisualContent]()
#Set visualization parameters
plot1.XAxis.ManualZoom = True
plot2.XAxis.ManualZoom = True
plot3.XAxis.ManualZoom = True
plot1.XAxis.ZoomRange = AxisRange(min,max);
plot2.XAxis.ZoomRange = AxisRange(min,max);
plot3.XAxis.ZoomRange = AxisRange(min,max);