Sort Pens on Time Series Chart Help

I created my pens using a script when the page loads. I was hoping they would be in order of the data's columns order. I tried adding to the columns item (self.props.plots[0].trends[0].columns) to sort, but having no luck. When I add manually and not via script to columns, the order is loading correctly. Any thoughts on this?

Pens

Dataset

Show your script.

(I suspect you have dictionary involved somewhere--they don't retain order.)

1 Like

Since this is an "Ignition" question I suggest that you move it to that section rather than "General Discussion". Also add the Perspective or Vision tag when it's application specific.

1 Like

image

First off post code, not pictures of code, with sensitive parts redacted as necessary:

Moving onto the ordering problem, you are iterating through the response from browseTags, so you are likely at the mercy of whatever order that function returns the tags in.

If you just want alphabetical ordering you can make use of operator.itemgetter to sort the resulting list before returning it. Something along the lines of

data = sorted(data, key=operator.itemgetter('alias'))

right before assigning the data to self.custom.data should work.

If you want specific ordering you'll probably have to do something like use a separate list that has the tag names in the preferred order, that you can then compare against and move items in the data variable to match positions/order.

Thanks for the heads up on posting.

When I run the script in the Script Console, the order is correct. Hence the use of 'ASC' to sort. The order of the data is correct in the binding (column order). Visually it is incorrect.

This is a set device list. So it was already alphabetized. Just seems weird the pen order changes in the legend.

Missed that when I was reading through.

That list is sorted by the actual tag path, are you sure that your tag aliases line up with the order of your sensor Ids? (ie, sensors 4-7 are Fluid 1-4, sensors8-11 are gas 1-4, etc). Just trying to think of anything that might throw off the order.

It could also just be an issue with how the legend is created internally and you might not be able to control it.

1 Like

That is what I am worried about. I just want to sort the legend. It looks like it is partially creating it in the correct order. The stuff in the middle is getting zippered together it seems.

The tag order is what we are trying to use as it groups the sensors. At some point the names (Temp1, etc) will change. So the key is to sort them by type. So alphabetical is not necessarily the goal.

At the end of the day the legend isn't super important. But from a visual standpoint, it looks wrong to me. I feel like this should be something simple to sort.

image