# Troubleshooting Vision Chart

**URL:** <https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [March 5, 2025, 8:36pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290 "2025-03-05T20:36:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 5, 2025, 8:36pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/1 "2025-03-05T20:36:26Z")

</div>

I am updating an application that uses a chart. I'm trying to merge two datasets to populate a standard chart in vision. However, the values that I am seeing for the new column show are not showing the correct values. Below is the python code that I wrote in an event script on a refresh button.

 ![Merged DS 2025-03-05](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/874f2f49bd727abfdd9ce6e4cdfe42694809d3a5.png)

The highlight column that I added seem to show indexes and not actual values.

```python
DS = event.source.parent.Data

# Validate dataset -- the button is disabled if there are no records in the event.source.parent.Data dataset
system.util.getLogger("Debug").info("Row count: {}".format(DS.rowCount))

#if DS is None or DS.rowCount == 0:
# system.gui.errorBox("Dataset is empty. Cannot proceed.", "No Spectro Data for Location!")
    # raise ValueError("Dataset is empty. Cannot proceed.")

# Add a new column to the dataset
#columnName = "oxygen"
#columnData = [
# float(i) for i in range(DS.rowCount)
#] 
#DS2 = system.dataset.addColumn(DS, columnData, columnName, float)
headers = list(DS.columnNames) + ["oxygen"]
data = [[DS.getValueAt(i,col) for col in range(DS.columnCount)] + [float(i)]
		for i in range(DS.rowCount)
]
DS2 = system.dataset.toDataSet(headers, data)
event.source.parent.Data_2 = DS2

#Logging the dataset to confirm the change:
system.util.getLogger("Debug").info("Columns after addColumn: {}".format(DS2.getColumnNames()))

# Retrieve dropdown selection parameters
DDElement = event.source.parent.getComponent("DDElement")
NDX = DDElement.selectedIndex
if NDX < 0:
    raise ValueError("No selection made in the dropdown.")

Column = DDElement.selectedLabel
Limit = DDElement.data.getValueAt(NDX, "limit")

# Validate column selection
system.util.getLogger("Debug").info("DS2 columns: {}".format(DS2.getColumnNames()))

if Column not in DS2.getColumnNames():
    system.util.getLogger("Validation").error("Column {} does not exist in dataset.".format(Column)) 
  

# Extract data from the selected column
Ordinal = DS2.getColumnIndex(Column)
Samples = DS2.getColumnAsList(Ordinal)

# Validate samples
if not Samples or len(set(Samples)) == 1:
    raise ValueError("Samples must contain at least two distinct values.")

# Generate I-MR control chart data
IMR = ControlCharts.I_MR(Samples, Limit)
if not IMR or len(IMR) != 2:
    raise ValueError("Invalid I-MR control chart data generated.")

# Update control chart components
Chart_I = event.source.parent.getComponent("Chart_I")
Chart_I.Data = system.dataset.filterColumns(IMR[0], ("Sample", "I"))
Chart_I.Limits = system.dataset.filterColumns(
    IMR[0], ("Sample", "XBAR", "UCL", "LCL", "Limit" if Limit != 0 else ""))

Chart_MR = event.source.parent.getComponent("Chart_MR")
Chart_MR.Data = system.dataset.filterColumns(IMR[1], ("Sample", "MR"))
Chart_MR.Limits = system.dataset.filterColumns(IMR[1], ("Sample", "RBAR", "UCL", "LCL"))

# Update trend chart
if "post_date" in DS2.getColumnNames():
    event.source.parent.getComponent("ChartTrend").Data = system.dataset.filterColumns(DS2, ("post_date", Column))
else:
    system.util.getLogger("Validation").error("Column 'post_date' not found in dataset.")

```

---

<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:** [March 5, 2025, 9:28pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/2 "2025-03-05T21:28:42Z")

</div>

I don't see where you are actually trying to combine the two datasets. Where is the oxygen data coming from?

This:

```python
data = [[DS.getValueAt(i,col) for col in range(DS.columnCount)] + [float(i)]
		for i in range(DS.rowCount)
]

```

is really putting the index on the end of your row.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 5, 2025, 10:37pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/3 "2025-03-05T22:37:43Z")

</div>

> [@Aisha\_Shiddat](#):
>
> ```python
> event.source.parent.Data_2 = DS2
> 
> ```

this property is bound to a query.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 6, 2025, 12:16am UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/4 "2025-03-06T00:16:57Z")

</div>

Is it possible for me to reference tags (indirect tags) to do this?

---

<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:** [March 6, 2025, 1:49pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/5 "2025-03-06T13:49:43Z")

</div>

> [@Aisha\_Shiddat](#):
>
> `event.source.parent.Data_2 = DS2`

You are not _getting_ information from that property. You are _writing_ the dataset you constructed to it. If the oxygen data is in the Data\_2 property, then you need to read it first.

As it stands, there is nothing that is reading the oxygen data that you want to add.

---

<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:** [March 6, 2025, 1:54pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/6 "2025-03-06T13:54:54Z")

</div>

Can you post the window as a sample, with valid incoming data?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 6, 2025, 3:05pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/7 "2025-03-06T15:05:27Z")

</div>

> [@Aisha\_Shiddat](#):
>
> The highlight column that I added seem to show indexes and not actual values.

It doesn't "seem" to be. It is.

> [@Aisha\_Shiddat](#):
>
> ```python
> data = [[DS.getValueAt(i,col) for col in range(DS.columnCount)] + [float(i)]
> for i in range(DS.rowCount)
> ]
> 
> ```

This line adds the row "index" converted to float to the columns of DS. You are not merging two datasets.

> [@Aisha\_Shiddat](#):
>
> this property is bound to a query.

If `event.source.parent.Data_2` is bound to a Query, then in your script you would be overwriting it.

> [@Aisha\_Shiddat](#):
>
> Is it possible for me to reference tags (indirect tags) to do this?

Yes.

You've also made this way harder than it needs to be. If for instance I have two datasets, and I want to copy the values of a column from ds2 into ds, then that code would look something like this:

```python
ds = event.source.parent.Data
ds2 = event.source.parent.Data_2

samples = ds2.getColumnAsList(ds2.getColumnIndex("oxygen"))
combinedData = system.dataset.addColumn(ds,samples,"oxygen",float)

```

> **[system.dataset.addColumn | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-dataset/system-dataset-addColumn)**
>
> Takes a dataset and returns a new dataset with a new column added or inserted into it.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 6, 2025, 8:20pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/8 "2025-03-06T20:20:09Z")

</div>

Ok, so both properties DS and DS2 are bound to queries that look at different tables in different databases. So... looking at this I need to read both databases and then append the results in another variable that represents the new dataset.

---

<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:** [March 6, 2025, 8:30pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-vision-chart/103290/9 "2025-03-06T20:30:55Z")

</div>

Yes. Datasets are immutable, to you need to read both, then manipulate them to make a new dataset that you use somewhere else.
