# Attached Histogram to Chart

**URL:** <https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [January 18, 2024, 6:23pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466 "2024-01-18T18:23:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [January 18, 2024, 6:23pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466/1 "2024-01-18T18:23:17Z")

</div>

What would be the best way to present a histogram to correlate with chart subplots?  
See to the right of this image...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/d/5de32743fcc17ff1881511b4bed516a3049788a7.png)

---

<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:** [January 18, 2024, 6:29pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466/2 "2024-01-18T18:29:48Z")

</div>

Huh. Probably have to lay a paintable canvas on top.

It's a great idea for inclusion in my NoteChart module. I'll put this on my to-do list.

---

<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:** [January 18, 2024, 6:51pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466/3 "2024-01-18T18:51:18Z")

</div>

Interesting, but what is the histogram trying to tell me?

---

<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:** [January 18, 2024, 6:58pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466/4 "2024-01-18T18:58:29Z")

</div>

It's helpful with Statistical Process Control, to "see" how tightly a signal is conforming to a setpoint.

---

<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:** [January 18, 2024, 7:59pm UTC](https://forum.inductiveautomation.com/t/attached-histogram-to-chart/84466/5 "2024-01-18T19:59:47Z")

</div>

Something quick and dirty (mostly dirty) using two charts.  
Assumes all dataset names match in each chart.

[Chart\_plus\_Histogram\_2024-01-18\_1444.zip](https://forum.inductiveautomation.com/uploads/short-url/8JpbQR2P5yqywGKG6igX6zHwThH.zip) (16.1 KB)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/7783ab73533f6d8ce7651648d5b3d93ee9fce039.png)

Script in button:

```python
from collections import Counter

mainChart = event.source.parent.getComponent('Chart')
histogram = event.source.parent.getComponent('Histogram')

xyPlot = mainChart.chart.getXYPlot()

for plot in xyPlot.subplots:

	datasetName = plot.dataset.name
	dataIn = getattr(mainChart, datasetName)
	counter = Counter(dataIn.getColumnAsList(1))
	dataOut = [[key, val] for key, val in sorted(counter.items())]
	setattr(histogram, datasetName, system.dataset.toDataSet(['x','y'], dataOut))

```
