# Combining Datasets

**URL:** <https://forum.inductiveautomation.com/t/combining-datasets/5711>\
**Category:** Ignition\
**Created:** [January 21, 2013, 7:08pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711 "2013-01-21T19:08:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordang](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jordang](https://forum.inductiveautomation.com/u/jordang)\
**Post date:** [January 21, 2013, 7:08pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711/1 "2013-01-21T19:08:11Z")

</div>

Hello,

I have two, single column datasets, that are the same length. One is a series of X values while the other is Y values. I’d like to combine them into a single two column dataset so it can be graphed.

From what I’ve seen it has to be done in script but I can’t seem to get the scripting right.

Any input is appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 21, 2013, 8:04pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711/2 "2013-01-21T20:04:19Z")

</div>

Try something like this. Obviously you’ll have your own datasets, and not the ones I’ve created in script for the purpose of this example:

```auto
toPyDS = system.dataset.toPyDataSet

xDataSet = toPyDS(system.dataset.toDataSet(['x'], [[1],[2],[3]]))
yDataSet = toPyDS(system.dataset.toDataSet(['y'], [[4],[5],[6]]))

xs = [row[0] for row in xDataSet]
ys = [row[0] for row in yDataSet]

rows = zip(xs, ys)
xyDataSet = system.dataset.toDataSet(['x', 'y'], rows)

event.source.parent.getComponent('Table').data = xyDataSet
```

---

<div class="post-metadata">

**Author:** ![jordang](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jordang](https://forum.inductiveautomation.com/u/jordang)\
**Post date:** [January 21, 2013, 8:59pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711/3 "2013-01-21T20:59:30Z")

</div>

That did exactly what I was looking for. However, when I tie it to a chart it has gives an error. I should have noted earlier that these are being read from an OPC server and are coming in as a string. After I do the split I guess the resulting dataset is all strings and the spaces or string datatype may be causing the chart error? Do I need to do something different with the base datasets?

Chart error: “IllegalArgumentException: Illegal type for X value: class java.lang.String (column ‘x’)”

Background:  
I remove the brackets from the string, then do a split on “,” in an expression to get the base dataset.

```auto
split(substring({Wavelengths}, 1, indexOf({Wavelengths}, "]")),",")
```

The resulting data set looks like this:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b35881ca7655b06da8dec14e5668be8e4e08ba2a.png)  
  
After running the code Kevin posted my combined dataset:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/83f71f318876457c5ba4083729fd7a1d2b18afa6.png)

Thanks again.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 21, 2013, 9:15pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711/4 "2013-01-21T21:15:09Z")

</div>

Casting the x and y values from strings to numbers before zipping may be the answer:

```auto
toPyDS = system.dataset.toPyDataSet

xDataSet = toPyDS(system.dataset.toDataSet(['x'], [['1.1'],['2.2'],['3.3']]))
yDataSet = toPyDS(system.dataset.toDataSet(['y'], [['4.4'],['5.5'],['6.6']]))

xs = [float(row[0]) for row in xDataSet]
ys = [float(row[0]) for row in yDataSet]

rows = zip(xs, ys)
xyDataSet = system.dataset.toDataSet(['x', 'y'], rows)

event.source.parent.getComponent('Table').data = xyDataSet
```

---

<div class="post-metadata">

**Author:** ![jordang](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jordang](https://forum.inductiveautomation.com/u/jordang)\
**Post date:** [January 21, 2013, 9:34pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/5711/5 "2013-01-21T21:34:22Z")

</div>

Perfect! Thanks for the help.
