# How to populate the Data Density of a Date Range component with historian data

**URL:** <https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384>\
**Category:** Ignition\
**Created:** [January 19, 2021, 4:45am UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384 "2021-01-19T04:45:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![philip](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/philip/32/5709_2.png) [@philip](https://forum.inductiveautomation.com/u/philip)\
**Post date:** [January 19, 2021, 4:45am UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/1 "2021-01-19T04:45:55Z")

</div>

I would like to be able to obtain a dataset of available timestamps from the historian to display on a data range component using the Data Density property.

Basically exactly how the Easy Chart does here in red:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9cdb05ba13139a0154fd7bcf5bd5c3e6f5429a9f.png)

I don’t see a way to get this data from a Tag History binding so I think it will need to be scripted. What is the most efficient way to get this data from the historian?

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [January 19, 2021, 5:30am UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/2 "2021-01-19T05:30:39Z")

</div>

Put this in Data Density:

```auto
SELECT 
	eventtime
FROM 
	alarm_events 
WHERE 
	eventtime BETWEEN '{Root Container.Date Range.outerRangeStartDate}' AND '{Root Container.Date Range.outerRangeEndDate}' 
ORDER BY 
	eventtime ASC

```

---

<div class="post-metadata">

**Author:** ![philip](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/philip/32/5709_2.png) [@philip](https://forum.inductiveautomation.com/u/philip)\
**Post date:** [January 19, 2021, 6:03am UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/3 "2021-01-19T06:03:08Z")

</div>

Unfortunately this is for historian data, not alarm events.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 19, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/4 "2021-01-19T19:29:20Z")

</div>

[https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagDensity](https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagDensity)?

---

<div class="post-metadata">

**Author:** ![philip](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/philip/32/5709_2.png) [@philip](https://forum.inductiveautomation.com/u/philip)\
**Post date:** [January 20, 2021, 4:50am UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/5 "2021-01-20T04:50:40Z")

</div>

queryTagDensity only returned the count of the tag for the range given - so I would have to call it a lot of times to fill in the Data Density.

After taking a fresh look at this, I ended up solving this by binding a custom property dataset to a Tag History query return the Percent Good aggregation and a 10,000 fixed sample size (any less and the data density will look choppy). Surprisingly the performance was pretty good for this.

I then wrote a propertyChange script that whenever the above custom property changes creates a new dataset multiplying the Percent Good by 100 and then assigns this to the Date Range components densityData property. I also store the time stamp of the last good value in a custom property for other uses. Script is like this:

```auto
if event.propertyName == 'Density':
  density = event.source.Density
  
  rows = []
  for i in range(density.getRowCount()):
    percentGood = density.getValueAt(i, 'weight')
    timeStamp = density.getValueAt(i, 't_stamp')
    if percentGood > 0:
      event.source.LastValidDate = timeStamp
    row = [timeStamp, percentGood * 100.0]
    rows.append(row)
    
  event.source.densityData = system.dataset.toDataSet(['t_stamp', 'weight'], rows)

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Shaw](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Ryan\_Shaw](https://forum.inductiveautomation.com/u/Ryan_Shaw)\
**Post date:** [March 2, 2026, 3:17pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-the-data-density-of-a-date-range-component-with-historian-data/42384/6 "2026-03-02T15:17:10Z")

</div>

I’m also trying to use the data density dataset to highlight where data exists for a date range object. My dates are not continuous so I manually create the density

```python
    ds = self.getComponent('Power Table').data
	t_stamp = []
	for row in range(ds.getRowCount()):
		start = ds.getValueAt(row, 'StartDate')
		end = ds.getValueAt(row, 'EndDate')
		
		delta = system.date.hoursBetween(start, end)
		
		for i in range(delta):
			dt = system.date.addHours(start, i)
			t_stamp.append(dt)
	
	weight = [100] * len(t_stamp)
	
	data = [[t, w] for t, w in zip(t_stamp, weight)]
	headers = ['t_stamp', 'weight']
	ds = system.dataset.toDataSet(headers, data)
	self.getComponent('Date Range').densityData = ds

```

The problem I’m having is the highlight color is very weak even though I’ve set the high density color to 255,0,0 with no opacity.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/b/9b05e8a8c0a8992cc4dfd18c6c535f62a126585c.png)

How can I adjust this to get a bold red color like in the original post’s screen shot?
