How can i convert this array into a dataset? I'm trying to use a transform expression to convert the data to a dataset that i can use for a table.
Here is the new dataset tag i want it to go to with a transform expression.
Here's what it looks like in that dataset tag.
I don't think you need to do a transform. Just bind the table
Each item in the list (
0, 1, 2, etc.) becomes a table row. Each element in the item becomes a table column.
I agree with @Transistor, pretty sure there is no need to convert it.
In fact, you should be able to bind directly to the tag and it be treated just like any dataset object. I know I do this in scripting in a couple of places and I've never had to reconstruct the dataset.
That being said, I don't think there is any expression function that will convert the Count object array to a dataset. If you read the documentation it says that (basically) only datasets and PyDatasets can be coerced into a dataset using the
You can do it with a Script transform, though.
headers = 
data = 
for row in value:
if not headers:
headers = row.keys()
data.append([val for key,val in row.iteritems()])
EDIT: I should note that, this script will error if the object lengths are uneven (e.g. any object has more or less keys than another object). You can get around that by supplying a list of headers and filtering the objects for only those keys.
EDIT 2: Also, noticed that you are using an expression binding to bind to only a property. I don't know for sure, but I would believe there is some unneeded overhead there for the expression to parse and look up the property. A property binding would probably be better here.
Yes the table works with the data like it is, its just not in the correct order. I want the table to be hour, actual, and then std and I couldn't figure out a way to change the order it shows in the table, I figured if I converted it to a dataset then i would be able to change the dataset so the table looked correct. I'm pretty new to perspective so I don't really know the correct way to do it so i'm trying a bunch of things to see what works.
Add columns and set the fields in the order that you want. Away from my computer atm so can’t provide a screen grab.
Thanks for your help, the table does work with the data from the original tag, I was trying to reconstruct the dataset so I could make the table look correct. I'm new to perspective so I'm still learning how this stuff works.
I do have another question for you guys. How do I create a dataset property in Perspective? I only see value, object, and array in the dropdown when I create a new property. I have a few already but they're system generated from being bound to a SQL query. Do I have to use a script like above to create the dataset first? or is there a manual way to do it?
There is no way to make a "dataset" type object by hand Although, that's not a bad idea for a suggestion. The default is the Array of Objects, as you have it.
You can change the order of the columns (and insure that order is fixed) by using the
props.columns on the table. Add the number of columns that you have in your table and then set the field for each column as you want them to appear in the table.
Thank you. That worked great.
I always create an expression binding with
toDataset(''). After pressing apply, I then remove the binding I just created and edit the dataset object manually.