Spotfire Ironpython: 运行脚本后,筛选器消失?

huangapple go评论80阅读模式
英文:

Spotfire Ironpython: Filters disappear after running a table through script?

问题

我有一个数据表,我将其放入一个按钮的脚本中。它会对表格进行各种可视化格式化,但在处理后,右侧的筛选栏中的项目消失了,并且我收到了以下错误:

XmlHttpRequest 失败。内部服务器错误
读取错误 (-1):{"viewId":"ceb0fbf6-5bd1-4b3f-a191-a431f1ffaa0a","method":"InitializeFilter","args":"{"id":"97b12241-cb78-46c1-8b24-97cb789b34d2","filterContainerId":"poppedFilter11"}"}
XMLHttpRequest: {"readyState":4,"responseText":"","status":500,"statusText":"内部服务器错误"}

这是我的脚本:

from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
from Spotfire.Dxp.Application import Layout
page = Document.Pages.AddNew()

#visualization (I copy this for a total of 4 visualizations)

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "Title"
myVis.XAxis.Expression = '[Date]'
myVis.YAxis.Expression = '[Item1]'
myVis.ColorAxis.Expression = '[Item2]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '<[Item3]>'
myVis.LineConnection.UseMarkerColor = True

#format

lst = []
for visual in page.Visuals:
lst.append(visual)
format = Layout.LayoutDefinition()
format.BeginStackedSection(1)
format.Add(lst[0])
format.Add(lst[2])
format.BeginSideBySideSection(1)
format.Add(lst[1])
format.Add(lst[3])
format.EndSection()
format.EndSection()

page.ApplyLayout(format)

在表格中,我还有另一列,我希望能够通过筛选来使用。当我再次打开表格时,看起来另一列已经消失了(在可视化中未被使用)。我认为我的脚本对表格进行了某种操作,以清除所有筛选,但我不知道如何修复它。

英文:

I have a data table that I put into a script in a button. It takes the table and formats various visualizations on it, but after it goes through, the items in the filter bar on the right disappears and I get this error:

XmlHttpRequest failed. Internal Server Error
Read error (-1): {"viewId":"ceb0fbf6-5bd1-4b3f-a191-a431f1ffaa0a","method":"InitializeFilter","args":"{"id":"97b12241-cb78-46c1-8b24-97cb789b34d2","filterContainerId":"poppedFilter11"}"}
XMLHttpRequest: {"readyState":4,"responseText":"","status":500,"statusText":"Internal Server Error"}

This is my script:

from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
from Spotfire.Dxp.Application import Layout
page = Document.Pages.AddNew()

#visualization (I copy this for a total of 4 visualizations)

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = &quot;Title&quot;
myVis.XAxis.Expression = &#39;\[Date\]&#39;
myVis.YAxis.Expression = &#39;\[Item1\]&#39;
myVis.ColorAxis.Expression = &#39;\[Item2\]&#39;
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = &#39;\&lt;\[Item3\]\&gt;&#39;
myVis.LineConnection.UseMarkerColor = True

#format

lst = []
for visual in page.Visuals:
lst.append(visual)
format = Layout.LayoutDefinition()
format.BeginStackedSection(1)
format.Add(lst\[0\])
format.Add(lst\[2\])
format.BeginSideBySideSection(1)
format.Add(lst\[1\])
format.Add(lst\[3\])
format.EndSection()
format.EndSection()

page.ApplyLayout(format)

In the table I have another column that I want to be able to filter by. When I open the table again, it looks like that other column has disappeared (it was unused in the visualizations). I'm thinking my script did something to the tables to wipe out all of the filters but I have no idea how to fix it

答案1

得分: 0

你的脚本出现了错误。

  • 我修复了缩进,
  • 删除了所有反斜杠,
  • 它抱怨 lst[] 的索引超出范围。所以我创建了四个相同的 Visuals。

页面已创建,过滤面板看起来有点奇怪。
然而,这似乎纯粹是你创建新页面的效果。默认值可能不是人们所期望的。如果我添加一个 AutoConfigure() 并将过滤面板设置为可见,它看起来会好一些。

我不知道这个额外的列是什么意思,但现在脚本似乎可以工作。

from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
from Spotfire.Dxp.Application import Layout
page = Document.Pages.AddNew()
page.Title = '我的新页面'
page.AutoConfigure()
filter_panel = page.FilterPanel
filter_panel.Visible = True

# 可视化(我将此复制了总共4次)

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "标题1"
myVis.XAxis.Expression = '[日期]'
myVis.YAxis.Expression = '[项目1]'
myVis.ColorAxis.Expression = '[项目2]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '<[项目3]>'
myVis.LineConnection.UseMarkerColor = True

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "标题2"
myVis.XAxis.Expression = '[日期]'
myVis.YAxis.Expression = '[项目1]'
myVis.ColorAxis.Expression = '[项目2]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '<[项目3]>'
myVis.LineConnection.UseMarkerColor = True

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "标题3"
myVis.XAxis.Expression = '[日期]'
myVis.YAxis.Expression = '[项目1]'
myVis.ColorAxis.Expression = '[项目2]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '<[项目3]>'
myVis.LineConnection.UseMarkerColor = True

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "标题4"
myVis.XAxis.Expression = '[日期]'
myVis.YAxis.Expression = '[项目1]'
myVis.ColorAxis.Expression = '[项目2]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '<[项目3]>'
myVis.LineConnection.UseMarkerColor = True

# 格式化

visuals = list(page.Visuals)
format = Layout.LayoutDefinition()
format.BeginStackedSection(1)
format.Add(visuals[0])
format.Add(visuals[2])
format.BeginSideBySideSection(1)
format.Add(visuals[1])
format.Add(visuals[3])
format.EndSection()
format.EndSection()

page.ApplyLayout(format)
英文:

Your script throws errors.

  • I fixed the indentation,
  • removed all the back slashes,
  • it complained about index out of range for lst[]. So I created the four identical
    Visuals.

The page is created and the filter panel does look a bit iffy.
However, this seems purely the effect of how you create the new page. The defaults must be not what one expects. If I add an AutoConfigure() and set the filter panel to visible, it looks better.

I don't know what this extra column means, but now the script seems to work.

from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
from Spotfire.Dxp.Application import Layout
page = Document.Pages.AddNew()
page.Title=&#39;My New Page&#39;
page.AutoConfigure()
filter_panel=page.FilterPanel
filter_panel.Visible=True
#visualization (I copy this for a total of 4 visualizations)
myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = &quot;Title1&quot;
myVis.XAxis.Expression = &#39;[Date]&#39;
myVis.YAxis.Expression = &#39;[Item1]&#39;
myVis.ColorAxis.Expression = &#39;[Item2]&#39;
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = &#39;&lt;[Item3]&gt;&#39;
myVis.LineConnection.UseMarkerColor = True
myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = &quot;Title2&quot;
myVis.XAxis.Expression = &#39;[Date]&#39;
myVis.YAxis.Expression = &#39;[Item1]&#39;
myVis.ColorAxis.Expression = &#39;[Item2]&#39;
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = &#39;&lt;[Item3]&gt;&#39;
myVis.LineConnection.UseMarkerColor = True
myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = &quot;Title3&quot;
myVis.XAxis.Expression = &#39;[Date]&#39;
myVis.YAxis.Expression = &#39;[Item1]&#39;
myVis.ColorAxis.Expression = &#39;[Item2]&#39;
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = &#39;&lt;[Item3]&gt;&#39;
myVis.LineConnection.UseMarkerColor = True
myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = &quot;Title4&quot;
myVis.XAxis.Expression = &#39;[Date]&#39;
myVis.YAxis.Expression = &#39;[Item1]&#39;
myVis.ColorAxis.Expression = &#39;[Item2]&#39;
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = &#39;&lt;[Item3]&gt;&#39;
myVis.LineConnection.UseMarkerColor = True
#format
visuals = list(page.Visuals)
format = Layout.LayoutDefinition()
format.BeginStackedSection(1)
format.Add(visuals[0])
format.Add(visuals[2])
format.BeginSideBySideSection(1)
format.Add(visuals[1])
format.Add(visuals[3])
format.EndSection()
format.EndSection()
page.ApplyLayout(format)

huangapple
  • 本文由 发表于 2023年7月18日 05:29:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708187.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定