# Bar chart (report) static line

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445>\
**Category:** Ignition\
**Created:** [June 13, 2018, 2:02pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445 "2018-06-13T14:02:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![leversole](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@leversole](https://forum.inductiveautomation.com/u/leversole)\
**Post date:** [June 13, 2018, 2:02pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/1 "2018-06-13T14:02:15Z")

</div>

I have a simple bar chart in a report I am using SQL to fill the chart. I need a “static” line at a certain value to use as a straight “max” line. I can draw a line, but as the scale of the chart changes dynamically, the line is no longer where it is supposed to be. Is there some code I could add to the chart to position the line appropriately? Or some other method?

Thanks

---

<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:** [June 13, 2018, 3:05pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/2 "2018-06-13T15:05:50Z")

</div>

Untested, but you would need something like this in the chart configuration script:

```auto
from org.jfree.chart.plot import ValueMarker
marker = ValueMarker(123) #point on range axis to label
marker.setLabel("Some Marker")
chart.getPlot().addRangeMarker(marker)

```

---

<div class="post-metadata">

**Author:** ![leversole](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@leversole](https://forum.inductiveautomation.com/u/leversole)\
**Post date:** [June 13, 2018, 3:52pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/3 "2018-06-13T15:52:54Z")

</div>

Thanks! Will give it a try!

---

<div class="post-metadata">

**Author:** ![leversole](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@leversole](https://forum.inductiveautomation.com/u/leversole)\
**Post date:** [June 13, 2018, 4:02pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/4 "2018-06-13T16:02:21Z")

</div>

That worked (of course)…my next question is are there other properties I can set for the marker, where can I learn about them? I only need line weight and color!

Thanks

---

<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:** [June 13, 2018, 4:09pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/5 "2018-06-13T16:09:59Z")

</div>

The best reference is JFreeChart's API/Javadoc; for instance, the ValueMarker class is defined here:  
[http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/ValueMarker.html](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/ValueMarker.html)

Line weight and color can be set by using one of the overloaded constructors;

> ValueMarker(double value, Paint paint, Stroke stroke)

Paint is a base Java class that's implemented by Color, so you can just use `system.gui.color(r, g, b)`.  
Stroke is easiest to define with the [`BasicStroke`](https://docs.oracle.com/javase/7/docs/api/java/awt/BasicStroke.html) class - so just import that class, and use a new instance in the call when you create a new `ValueMarker` instance.

---

<div class="post-metadata">

**Author:** ![leversole](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@leversole](https://forum.inductiveautomation.com/u/leversole)\
**Post date:** [June 13, 2018, 4:12pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/6 "2018-06-13T16:12:33Z")

</div>

Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 22, 2020, 9:38pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/7 "2020-01-22T21:38:05Z")

</div>

Is it possible to do similar coding to add a reference line to the Bar Chart object in the Vision Module?

---

<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 22, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/8 "2020-01-22T21:52:52Z")

</div>

Yes, similar code should work; I don’t know exactly what differences would be required offhand.

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 22, 2020, 10:06pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/9 "2020-01-22T22:06:32Z")

</div>

Using code I successfully used in a report’s bar chart, I set this script up in the Event Handler PropertyChange:

from java.awt import BasicStroke   
from org.jfree.chart.plot import ValueMarker  
goal = 0.5

s = BasicStroke(  
4.0, #width  
BasicStroke.CAP\_ROUND, #cap  
BasicStroke.JOIN\_ROUND, #join  
1.0)

m = ValueMarker(goal, system.gui.color(255, 10, 10), s)  
chart = event.source.parent.getComponent(“Bar Chart”)  
chart.getPlot().addRangeMarker(m)

When it runs, I get the error: AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute ‘getPlot’

---

<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 22, 2020, 10:20pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/10 "2020-01-22T22:20:07Z")

</div>

Add a `getChart()` after `getComponent("Bar Chart")` - `getComponent` gives you the Ignition component, from which you need to `getChart()` to get the underlying JFreeChart object.

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 22, 2020, 10:32pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/11 "2020-01-22T22:32:09Z")

</div>

I guess I don’t know the syntax for that:

chartIgn = event.source.parent.getComponent(“Bar Chart”)  
chart = chartIgn.getchart()  
chart.getPlot().addRangeMarker(m)

AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute ‘getchart’

---

<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 22, 2020, 10:39pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/12 "2020-01-22T22:39:40Z")

</div>

`getChart()`, not `getchart()` - has to match case.

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 22, 2020, 10:44pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/13 "2020-01-22T22:44:54Z")

</div>

Ugh - sorry. Yep, that works.

I ended up consolidating it to:  
chart = event.source.parent.getComponent(“Bar Chart”).getChart()

Thanks!

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 29, 2020, 6:31pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/14 "2020-01-29T18:31:19Z")

</div>

This is working well in my dashboards. On the reports, which is where I first got it working, the reference line shows up in the preview in the report module, but not in the PDF when the report is emailed. Everything else renders in the PDF as expected.

Any ideas what’s preventing the line from rendering in the PDF?

The code is:  
from java.awt import BasicStroke   
from org.jfree.chart.plot import ValueMarker  
goal = 0.5

```
s = BasicStroke(
	4.0, #width
	BasicStroke.CAP_ROUND, #cap 
	BasicStroke.JOIN_ROUND, #join
	1.0) #, #miterLimit
	#[2, 4, 8, 16, 32], #dash pattern
	#0.0) #dash_phase_offset

m = ValueMarker(goal, system.gui.color(255, 10, 10), s)
#m.setLabel("Target Over")
chart.getPlot().addRangeMarker(m)
```

---

<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 29, 2020, 6:32pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/15 "2020-01-29T18:32:55Z")

</div>

`system.gui` functions only exist in client/designer scope. Manually import `java.awt.Color` (or use a project script):

```auto
from java.awt import Color
red = Color(255, 10, 10)

```

---

<div class="post-metadata">

**Author:** ![ajrowe](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ajrowe](https://forum.inductiveautomation.com/u/ajrowe)\
**Post date:** [January 29, 2020, 6:53pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/16 "2020-01-29T18:53:48Z")

</div>

Yep, that fixed it. Thanks again!

---

<div class="post-metadata">

**Author:** ![joe.hammond](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@joe.hammond](https://forum.inductiveautomation.com/u/joe.hammond)\
**Post date:** [February 19, 2020, 3:10pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/17 "2020-02-19T15:10:53Z")

</div>

I found the Marker Label is partially cutoff on the left bar. This is what I did to correct this.  
RectangleInsets(top,left,bottom,right)

```
from org.jfree.ui import RectangleInsets
m.setLabelOffset(RectangleInsets(5,10,0,0))

```

Before:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/76402e189d3075e0fb8e723d4f88c8d38e950ff7.png)

After:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/69037d5e2fe5062614b286cc71fe58d1716d8f8a.png)

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 16, 2020, 1:49am UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/18 "2020-06-16T01:49:58Z")

</div>

How can you get this to work on a Chart component that has sub plots?  
I have managed to get it working when i only have one dataset, but i’ve got another component with two datasets on different plots.  
I’d like to add a different marker to each plot. I’ve tried calling:  
`plot = event.source.getChart().getPlot()`  
But i suspect there needs to be a way to tell it which plot im interested in? Strangely i’m not getting any marker showing up, nor any errors.

---

<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:** [June 16, 2020, 3:35pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/19 "2020-06-16T15:35:25Z")

</div>

If `getPlot()` returns a `org.jfree.chart.plot.CombinedDomainXYPlot` (you can import that class and check `isinstance`), then it will have a `getSubplots()` method that returns, naturally, the subplots, which is where you want to actually apply your markers.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 16, 2020, 8:11pm UTC](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445/20 "2020-06-16T20:11:35Z")

</div>

Thanks, that worked a treat. I did try and look at the JFree chart docs before posting a question, but i don’t seem to be very good at navigating it. For instance i thought getPlot() returned “org.jfree.chart.plot”, and i was looking at those methods, which doesn’t have getSubplot().

Could you give me a hint of how you traced that out?

[Next page](https://forum.inductiveautomation.com/t/bar-chart-report-static-line/18445.md?page=2)
