# Creating trends by using script

**URL:** <https://forum.inductiveautomation.com/t/creating-trends-by-using-script/108662>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [July 18, 2025, 10:23am UTC](https://forum.inductiveautomation.com/t/creating-trends-by-using-script/108662 "2025-07-18T10:23:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauravavhad.1989](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@gauravavhad.1989](https://forum.inductiveautomation.com/u/gauravavhad.1989)\
**Post date:** [July 18, 2025, 10:23am UTC](https://forum.inductiveautomation.com/t/creating-trends-by-using-script/108662/1 "2025-07-18T10:23:35Z")

</div>

```python
import system
import system.date

columns = [
    "name", "tagPath", "aggregationMode", "axis", "subplot", "enabled",
    "penColor", "dashPattern", "renderStyle", "lineWeight", "shape",
    "fillShape", "labels", "group_name", "digital", "overrideAutoColor",
    "hidden", "userSelectable", "sortOrder", "userRemovable"
]

rows = [
    ["Temperature", "[EMS_TRIAL_DATABASE]tag_1-tag_11/tag_1", "Average", 0, 0, True,
     0xFF0000, "", "Line", 2, 0, False, "", "", False, False, False, True, 1, True],

    ["Pressure", "[EMS_TRIAL_DATABASE]tag_1-tag_11/tag_2", "Average", 0, 0, True,
     0x000FFF, "", "Line", 1, 0, False, "", "", False, False, False, True, 2, True]
]

dataset = system.dataset.toDataSet(columns, rows)
print "Columns:", dataset.getColumnNames()

chart = event.source.parent.getComponent("Easy Chart")
chart.tagPens = system.dataset.toDataSet([], []) # Clear first

endTime = system.date.now()
startTime = system.date.addHours(endTime, -2)

chart.startDate = startTime
chart.endDate = endTime
chart.tagPens = dataset

```

i am using this script to create trends in easy chart in vision.but i am getting the following error

**Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1**  
\*\* at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source)\*\*  
\*\* at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Unknown Source)\*\*  
\*\* at java.base/jdk.internal.util.Preconditions.checkIndex(Unknown Source)\*\*  
\*\* at java.base/java.util.Objects.checkIndex(Unknown Source)\*\*  
\*\* at java.base/java.util.ArrayList.get(Unknown Source)\*\*  
\*\* at com.inductiveautomation.ignition.common.AbstractDataset.getColumnType(AbstractDataset.java:105)\*\*  
\*\* at com.inductiveautomation.factorypmi.application.components.chart.easychart.PenData.setData(PenData.java:94)\*\*  
\*\* at com.inductiveautomation.factorypmi.application.components.chart.easychart.TagHistoryPenDatasource.setData(TagHistoryPenDatasource.java:99)\*\*  
\*\* at com.inductiveautomation.factorypmi.application.components.chart.easychart.AbstractChartQuery.handleQueryReturnedValue(AbstractChartQuery.java:146)\*\*  
\*\* at com.inductiveautomation.factorypmi.application.gateway.QueryManager$HandleReturnValueTask.run(QueryManager.java:486)\*\*  
\*\* at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventQueue$4.run(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventQueue$4.run(Unknown Source)\*\*  
\*\* at java.base/java.security.AccessController.doPrivileged(Unknown Source)\*\*  
\*\* at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)\*\*  
\*\* at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)\*\*

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 18, 2025, 11:14am UTC](https://forum.inductiveautomation.com/t/creating-trends-by-using-script/108662/2 "2025-07-18T11:14:25Z")

</div>

Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).  
Then you can edit your post to format the code block and format the error text. Thanks.

---

<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:** [July 18, 2025, 12:54pm UTC](https://forum.inductiveautomation.com/t/creating-trends-by-using-script/108662/3 "2025-07-18T12:54:07Z")

</div>

A few things:

1. Do not import `system`, or `system.date`
2. There is no need to "clear" the dataset. Datasets are immutable, so writing over it with the new dataset is sufficient.
3. You don't need to create a list of headers, you can just get the headers from the tagPens dataset. This will prevent you from missing a column that the chart is expecting.
4. You sould use actual `java.awt.Color` objects instaed of hex values.
5. Be sure to note the types of the columns, so that you can provide the type that the chart is expecting. For instance, the chart expects the render style to be an integer value. The chart component provides static variables for this purpose. You can also, just add a tag manually and edit the render style to find the integer values for each and use that.
6. The axis should be set to either the name of an Axis you have added to the chart or "Default Axis", which is what is added for you, other wise you may get unexpected results.

This code works as I would expect it to.

```python
from java.awt import Color
chart = event.source.parent.getComponent("Easy Chart")
columns = list(chart.tagPens.columnNames)

rows = [
    ["Temperature", "[EMS_TRIAL_DATABASE]tag_1-tag_11/tag_1", "Average", "Default Axis", 0, True,
     Color.RED, "", chart.STYLE_LINE, 2, 0, False, "", "", False, False, False, True, 1, True],

    ["Pressure", "[EMS_TRIAL_DATABASE]tag_1-tag_11/tag_2", "Average", "Default Axis", 0, True,
     Color(0,15,255), "", chart.STYLE_LINE, 1, 0, False, "", "", False, False, False, True, 2, True]
]

pens= system.dataset.toDataSet(columns, rows)
chart.endDate = system.date.now()
chart.startDate = system.date.addHours(chart.endDate, -2)
chart.tagPens = pens

```
