# Easy Chart - One tag, pen per bit

**URL:** <https://forum.inductiveautomation.com/t/easy-chart-one-tag-pen-per-bit/23391>\
**Category:** Ignition\
**Created:** [March 15, 2019, 6:37pm UTC](https://forum.inductiveautomation.com/t/easy-chart-one-tag-pen-per-bit/23391 "2019-03-15T18:37:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WPhan](https://avatars.discourse-cdn.com/v4/letter/w/82dd89/32.png) [@WPhan](https://forum.inductiveautomation.com/u/WPhan)\
**Post date:** [March 15, 2019, 6:37pm UTC](https://forum.inductiveautomation.com/t/easy-chart-one-tag-pen-per-bit/23391/1 "2019-03-15T18:37:22Z")

</div>

Is there a way to store history for an integer tag and then reference one bit of the integer to create multiple pens on a easy chart?

The problem is easy chart takes in a tag path and creates the chart from that path. I don’t see how I could use getBit() or write some script to pass in the bits that I want.

---

<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 16, 2019, 5:38pm UTC](https://forum.inductiveautomation.com/t/easy-chart-one-tag-pen-per-bit/23391/2 "2019-03-16T17:38:42Z")

</div>

There are times when the Easy Chart is not so easy. I don’t think there is a way to do what you’re looking for with the Easy Chart Component.

You could do this in the standard Chart component with some scripting.

- Query the Tag History
- Loop through the return data set
- For each value of the tag convert to a Binary List
- Create a Data set to hold the value of each bit at the given time stamp
- Move the data set into the chart for display

That would look something like the following. Please note this has not been completely tested.

```auto
#defining a function to do the decimal to binary conversion
def dec2Bin(intValue,intNumBits=0,leftToRight=False):
	
    intNumBits = abs(intNumBits)
	seqBits = []
	while intValue != 0:
		seqBits.append(intValue % 2)
		intValue = intValue/2
		
	if len(seqBits) < intNumBits:
		while len(seqBits) < intNumBits:
			seqBits.append(0)
	elif len(seqBits) > intNumBits and intNumBits != 0:
		while len(seqBits) > intNumBits:
			seqBits.pop()
	
	
	if leftToRight:
		seqBits.reverse()
	
	return seqBits

#grab the tag history for the last 30 mins		
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -30)

tagData = system.tag.queryTagHistory(paths=['integerTagPath'], startDate=startTime, endDate=endTime, returnSize=-1, aggregationMode="Maximum", returnFormat='Wide')

#the tagData data set will have the columns ['t_stamp', 'integerTagPath']
#we want to take the tag value at each t_stamp and expand it to the number
#of bits we're interested in

#for the sake of clarity I'm keeping the number of bits low
numBits = 4

headers = ['t_stamp','bit 0','bit 1','bit 2','bit 3']
chartData = []
for ts in range(tagData.rowCount):
	newRow = [tagData.getValueAt(ts,'t_stamp')]
	
	#get the bit values for the value from tag history
	bits = dec2Bin(tagData.getValueAt(ts,'integerTagPath'),numBits)
	
	for bit in bits:
		newRow.append(bit)
	chartData.append(newRow)

#now you have a data set relating the bit values
#to the time stamp from history
#just set the Chart Components Data property equal to
#this data set

```
