【发布时间】:2015-06-02 01:24:16
【问题描述】:
我有一个 csv 字符串输入 string_in="country,100,color"
谁能建议我如何在 spotfire 中使用 ironpython 脚本将此输入(string_in)附加到已经存在的
数据表可视化中。
谢谢。
【问题讨论】:
标签: ironpython spotfire
我有一个 csv 字符串输入 string_in="country,100,color"
谁能建议我如何在 spotfire 中使用 ironpython 脚本将此输入(string_in)附加到已经存在的
数据表可视化中。
谢谢。
【问题讨论】:
标签: ironpython spotfire
您需要引入一些不同的函数来通过脚本实现这一目标。我在下面有我的脚本,但总体而言,您要做的是将输入设置为数据源,然后将该数据源中的行添加到现有数据源中。我从 TIBCO 的 thisspotfire 教程中借了很多钱,并根据需要对其进行了修改,以使我们到达您想去的地方。因此,您可能会删除一些多余的导入。
我使用 datTab 作为脚本的输入参数作为我们想要添加行的数据表。
from Spotfire.Dxp.Data import AddRowsSettings
import System
from System import DateTime
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin
from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings
#First we need to create your data with some columns.
#Here I have a comma separated miniature table built up with
#a commented option for your variable itself. \r\n used for newline
textData = "name,values,category\r\ncountry,100,color\r\n"
#textData = "col1,col2,col3\r\n" + string_in + "\r\n"
#Memory Stream stuff. Simply just writing our variable
#into a place we can access to make a data source
stream = MemoryStream()
writer = StreamWriter(stream)
writer.Write(textData)
writer.Flush()
stream.Seek(0, SeekOrigin.Begin)
#you need settings to tell the system what stuff you're importing.
#here we define it is comma separated and what data types our columns are.
readerSettings = TextDataReaderSettings()
readerSettings.Separator = ","
readerSettings.AddColumnNameRow(0)
readerSettings.SetDataType(0, DataType.String)
readerSettings.SetDataType(1, DataType.Integer)
readerSettings.SetDataType(2, DataType.String)
textDataSource = TextFileDataSource(stream,readerSettings)
#We create some settings here automatically having the system match
#column names for us between the data table and our data source.
settings = AddRowsSettings(datTab,textDataSource)
#And finally we add the rows from our datasource with our settings.
datTab.AddRows(textDataSource,settings)
当然,您可以使用更长的输入变量使这更复杂,循环添加多行等。您也可以使用指向文件的 URL 而不是内存流的东西来遵循相同的过程。取决于您的输入类型。
如果您有任何问题,请告诉我。我试图评论重要部分,但如果需要,可以对特定功能进行进一步解释。
编辑:在我添加了几次不同的记录后,请参阅下面的屏幕截图@
【讨论】: