# EasyChart DB Pen Re-implementation

**URL:** <https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960>\
**Category:** Module Development\
**Tags:** sdk\
**Created:** [February 12, 2018, 11:15pm UTC](https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960 "2018-02-12T23:15:11Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [February 12, 2018, 11:15pm UTC](https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960/1 "2018-02-12T23:15:11Z")

</div>

Subtitle: **Following Alice Down the RabbitHole**

A couple weeks ago, fellow forum member @Sanderd17 [asked some questions](http://forum.inductiveautomation.com/t/visualising-theoretical-temperature-over-time/16732) about the EasyChart component’s X-Trace mode that prompted a modest change to my [NoteChart Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-notechart) to solve his problem.

While poking around my own source code, and the methods of the EasyChart that I override in my own subclass, I noticed a protected method that had avoided my gaze for the past three years: [PMIEasyChart.penIterator()](http://files.inductiveautomation.com/sdk/javadoc/ignition79/793/com/inductiveautomation/factorypmi/application/components/PMIEasyChart.html#penIterator--).

This prompted me to smack my forehead in anguish over a lost opportunity. I recall, sometime in 2015, asking @Carl.Gould how to hook up my [Time-Series Cache Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-time-series-database-cache) to the EasyChart, as it is much easier to design with than the Classic Chart. He made a casual comment about implementing my own Pen class. I don’t remember the wording, but I recall thinking it was some obscure extension-point-like construct that would make it possible to do so in the existing EasyChart component.

Well, I never figured it out in 2015, and it didn’t seem that important, so I filed it away in my future feature to-do list. Upon seeing that protected method in the Eclipse package explorer, I realized that I _ **couldn’t** _ make the EasyChart use the time-series cache, but I _ **could** _ make the EasyNoteChart use it.

And, since both the time-series cache and the EasyChart’s DB pens are generally intended to work with the wide tables produced by Transaction Groups, my cache’s keying on datasource, table name, timestamp column, and optional WHERE clause is the same as the Pen sorting done within the EasyChart’s [QueryGroupKey](http://files.inductiveautomation.com/sdk/javadoc/ignition79/793/com/inductiveautomation/factorypmi/application/components/chart/easychart/QueryGroupKey.html). Instead of creating a Pen from scratch and adding it alongside the other pen types, I could (and did) simply subclass the [DBPen](http://files.inductiveautomation.com/sdk/javadoc/ignition79/793/com/inductiveautomation/factorypmi/application/components/chart/easychart/DBPen.html) and divert its query operations to the cache subsystem. Sweet! (-:

Ah, but there’s a complication: These are two different modules, and I sell them separately. Someone may want the features of NoteChart but never use transaction groups. So I don’t want to merge them. Instead, I used reflection within NoteChart to find the necessary classes and methods in TS DB Cache, if they are both installed. And for completeness, I added a boolean property to `EasyNoteChart` (default true) to enable cache diversion _ **when possible** _. When so, `penIterator()` delivers my `CacheDBPen` instead of `DBPen` as needed, which neatly ties it into the chart’s data deliver logic.

So, when this new [beta of Time-Series Caching](https://www.automation-pros.com/ignition/Time%20Series%20Database%20Cache-2.0.3.1802112337.modl) is installed alongside the [new beta of NoteChart](https://www.automation-pros.com/ignition/NoteChart-1.8.2.1802102217.modl), all the DB pens used in any EasyNoteChart automatically use the cache. But if needed, the new boolean property can be turned off in specific charts to revert to regular queries.

Oh, and since it **_is_** a _ **cache** _ module, I made the histogram queries retrieve all relevant columns instead of just t\_stamp (but at a lower priority). It makes scrolling in historical mode _blistering_ fast, even with _ **millions** _ of rows of data per pen.

Anyways, ask yourself: Have I ever tried to load so much data into an EasyChart’s DB pen(s) that the query timed out? Have I run Realtime Charts with high resolution data on many clients at once, and brought my database to its knees?

---

<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:** [February 13, 2018, 9:42pm UTC](https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960/2 "2018-02-13T21:42:21Z")

</div>

If you try this, make sure you download the beta versions linked near the end above. No other versions have the necessary hooks.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [February 13, 2018, 11:15pm UTC](https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960/3 "2018-02-13T23:15:33Z")

</div>

Nice work, clever to re-route the pen’s datasource implicitly.

---

<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:** [February 14, 2018, 2:06am UTC](https://forum.inductiveautomation.com/t/easychart-db-pen-re-implementation/16960/4 "2018-02-14T02:06:26Z")

</div>

Thanks! As a side benefit, I don’t have to write a Chart Customizer. (-:
