I have a code, like this for an Action Control button:
from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Data import *
if (vis.TypeId == VisualTypeIdentifiers.BarChart):
vis.TypeId = VisualTypeIdentifiers.LineChart
vis.XAxis.Expression = "City"
elif (vis.TypeId == VisualTypeIdentifiers.LineChart):
vis.TypeId = VisualTypeIdentifiers.BarChart
vis.XAxis.Expression = "Country"
For some reason, this gives me the error:
'Visual' object has no attribute 'XAxis'
I have also tried casting it like:
vis = vis.As[VisualContent]()
and to encase the Expression like ie.:
vis.XAxis.Expression = "[Country]"
But with no success, and similar error. When I remove the XAxis expression part, the code works successfully, and I can switch between Line and Bar chart with a button click. What I want however, is also to change the X-axis between these two states. Any ideas?
EDIT
Here is my updated script, which returns another error:
if (vis.TypeId == VisualTypeIdentifiers.BarChart):
visual = vis.As[LineChart]()
#visual.TypeId = VisualTypeIdentifiers.LineChart
visual.XAxis.Expression = "[City]"
elif (vis.TypeId == VisualTypeIdentifiers.LineChart):
visual = vis.As[BarChart]()
#visual.TypeId = VisualTypeIdentifiers.BarChart
visual.XAxis.Expression = "[Country]"
Error:
File "<string>", line 7, in <module>
AttributeError: 'NoneType' object has no attribute 'XAxis'
Again, the visualization is added as a Script parameter named "vis".
vis = vis.As[Visualization]()instead ofvis = vis.As[VisualContent]()- Mark P.