# Charting data based on position in a dataset

**URL:** <https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [October 8, 2019, 3:49pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925 "2019-10-08T15:49:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 8, 2019, 3:49pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/1 "2019-10-08T15:49:48Z")

</div>

Hello,

I am creating a Load Curve in ignition. What I did is I have the data I need sorted into a dataset in the correct order (Not based on time but based on magnitude of the data). Now I am trying to get that data into a chart where the x axis is position in the dataset. Does anyone have experience with this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 8, 2019, 7:11pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/2 "2019-10-08T19:11:14Z")

</div>

Since it’s already sorted, you can extract the load values as a list from the dataset. Then you make a list of values to rank them, then put them into a new dataset.

```python
headers = ['rank', 'value']

#get load data as a list from the dataset
valueList = oldDataSet.getColumnAsList(oldDataSet.getColumnIndex('valueColumn'))

# make a list with the values from 0 to the length of the list of values
rankList = range(len(valueList))

# iterate through the values to create data for the new dataset.
data = [[rank, value] for rank, value in zip(rankList, valueList)] 

# make a new dataset
newDataSet = system.dataset.toDataSet(headers, data)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 8, 2019, 7:30pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/3 "2019-10-08T19:30:30Z")

</div>

What Jordan said, but I would simplify it with python’s [enumerate()](https://docs.python.org/2.7/library/functions.html#enumerate) function…

```auto
valueList = oldDataSet.getColumnAsList(oldDataSet.getColumnIndex('valueColumn'))
return system.dataset.toDataSet(['rank', 'value'], [[r, v] for r, v in enumerate(valueList)])

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 8, 2019, 7:42pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/4 "2019-10-08T19:42:38Z")

</div>

Or if we’re code-golfing, you can simplify the enumeration in @pturmel’s example a little bit with `[list(pair) for pair in enumerate(valueList)]`

But I should really just fix `toDataset` to allow you to pass a list of tuples directly 😉

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 8, 2019, 8:07pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/5 "2019-10-08T20:07:03Z")

</div>

getColumnAsList isn’t an attribute of a dataset… unless I am missing something.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 8, 2019, 9:32pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/6 "2019-10-08T21:32:35Z")

</div>

It is a method of a BasicDataset, the core of almost all of the implementations of the Dataset interface.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 8, 2019, 9:46pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/7 "2019-10-08T21:46:58Z")

</div>

Moved to the common Dataset interface in 8, which might be why it’s not working. @jparsons, are you working with a dataset returned from a history query, by chance?

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 9, 2019, 12:40pm UTC](https://forum.inductiveautomation.com/t/charting-data-based-on-position-in-a-dataset/28925/8 "2019-10-09T12:40:28Z")

</div>

Hmm no I am in 7.9. I am pulling from a table, the table is tied to tag history though.

The basic idea of what I am doing is I am trying to pull data from a specific time period defined by the user, I am then reorganizing all of those data points from high to low and displaying that on a chart.

The way I am accomplishing this right now is using a date range to get the date defined by the user and pulling tag history for that time period into a table. I am then using property change script on the date range block to reorganize the data.

So a very long-winded answer to your question. Yes, I am kind of using tag history. Not a SQL query, not sure which one you are asking about.
