# Dynamically Adding Dataset to Chart Customizer

**URL:** <https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640>\
**Category:** Ignition\
**Tags:** ignition79, vision\
**Created:** [August 3, 2022, 5:06pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640 "2022-08-03T17:06:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Micheal\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Micheal\_Shumaker](https://forum.inductiveautomation.com/u/Micheal_Shumaker)\
**Post date:** [August 3, 2022, 5:06pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/1 "2022-08-03T17:06:40Z")

</div>

I am working on pulling data from a database and separating it based on a timestamp before displaying it on a Classic Chart. The only thing is, I need to dynamically determine how many different timestamps there are when the script runs. Is there a way to dynamically add or delete datasets from the chart customizer so that each dataset has it’s own curve?

---

<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:** [August 3, 2022, 5:15pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/2 "2022-08-03T17:15:51Z")

</div>

You can add additional series to a chart in scripting, though that isn't the same as adding them to the chart customizer.

Here is an example that should give an idea of where to start.

> [@Prevent Easy Chart Plot from Moving](https://forum.inductiveautomation.com/t/prevent-easy-chart-plot-from-moving/46289/4):
>
> So the simplest way to achieve this is to use the Standard Chart Components Chart Customizer. Add an additional Dataset Add an additional X-Axis Configure the Axis Location to be on the TOP Add an additional Y-Axis Configure the Axis Location to be on the Right Assign the X and Y axis to the dataset in the Dataset Properties Tab Once you’ve done this all you need to do is generate the two datasets of data and assign them. The new dataset will appear as a custom property on the chart com…

If you need some help working through that, let us know what you have tried and where it didn't work.

---

<div class="post-metadata">

**Author:** ![Micheal\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Micheal\_Shumaker](https://forum.inductiveautomation.com/u/Micheal_Shumaker)\
**Post date:** [August 4, 2022, 1:19pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/3 "2022-08-04T13:19:26Z")

</div>

Thank you for the suggestion. I believe that once everything gets set up, this may be what I’m looking for. One thing that I didn’t understand, though, is where the chart that has the getPlot() method called on it is coming from in the sample.

---

<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:** [August 4, 2022, 3:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/4 "2022-08-04T15:40:19Z")

</div>

The sample is intended to be placed in the configureChart extension function of a Classic Chart component. However, you can modify the script to work outside of that function you just have to get a reference to the chart.

---

<div class="post-metadata">

**Author:** ![Micheal\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Micheal\_Shumaker](https://forum.inductiveautomation.com/u/Micheal_Shumaker)\
**Post date:** [August 5, 2022, 1:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/5 "2022-08-05T13:40:08Z")

</div>

I have used the following code (that was referenced in the first reply) to set up the legend for the chart.

```auto
legItems = plot.getLegendItems()
newLegItem = LegendItem(newDs.getSeriesKey(0), newDs.getSeriesKey(0), '', '', legItems.get(0).getLine(), legItems.get(0).getLineStroke(), Color.red)
legItems.add(newLegItem)
plot.setFixedLegendItems(legItems)

```

I understand what it is doing, but the odd thing is that no matter what I do the first dataset that I create and add to the chart has two entries in the legend. There is only one line plotted on the chart, but the first and only the first dataset ends up getting duplicated on the legend. Does anyone have any idea why this might be?

---

<div class="post-metadata">

**Author:** ![Micheal\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Micheal\_Shumaker](https://forum.inductiveautomation.com/u/Micheal_Shumaker)\
**Post date:** [August 5, 2022, 1:47pm UTC](https://forum.inductiveautomation.com/t/dynamically-adding-dataset-to-chart-customizer/62640/6 "2022-08-05T13:47:59Z")

</div>

Update: I discovered some extra dataset properties on the chart I was using for testing. Removing them solved my issue.
