# Chart Component Blank Space

**URL:** <https://forum.inductiveautomation.com/t/chart-component-blank-space/23422>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [March 18, 2019, 5:13pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422 "2019-03-18T17:13:54Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 5:13pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/1 "2019-03-18T17:13:54Z")

</div>

I am trying to learn JFreeChart within the Cart component in Ignition. I have figured out most of what i wanted but i can’t seem to get the last piece of the puzzle. I am trying to remove the space between the top of the component and the beginning of the chart. ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/dd9eae8c86fc47accc9a225abc0569777c4ec0bb.png)

I am using the following code to remove the space from the left and right sides but it doesn’t work for top and bottom.

```auto
	from org.jfree.ui import RectangleInsets	
	plot = chart.getPlot()
	plot.setInsets(RectangleInsets(0, 0, 0, 0))

```

Any suggestions would be greatly appreciated.

---

<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:** [March 18, 2019, 5:18pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/2 "2019-03-18T17:18:04Z")

</div>

Try [`setPadding()`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html#setPadding-org.jfree.chart.ui.RectangleInsets-) with your RectangleInsets.

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 5:57pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/3 "2019-03-18T17:57:38Z")

</div>

When I change “setInsets” to “setPadding” the script doesn’t work. Here is the entire code that i put on the “configureChart” extension function.

```auto
	from org.jfree.chart.renderer.category import StandardBarPainter	
	plot = chart.getPlot()
	renderer = plot.getRenderer()
	renderer.setBarPainter(StandardBarPainter())
	renderer.setShadowVisible(0)
	from java.awt import Color
	from java.awt import Font
	from org.jfree.chart.labels import StandardCategoryItemLabelGenerator
	from org.jfree.chart.labels import ItemLabelPosition
	from org.jfree.chart.labels import ItemLabelAnchor
	from org.jfree.ui import TextAnchor
	from org.jfree.ui import RectangleInsets	
	class myLabelGenerator(StandardCategoryItemLabelGenerator):
		def generateLabel(self,dataset,series, category):	
			value = dataset.getValue(series,category)	
			if value == 0:
				return None
			else:
				return str(int(value))
	plot = chart.getPlot()
	plot.setOutlinePaint(None)
	plot.setInsets(RectangleInsets(0, 0, 0, 0))
	renderer = plot.getRenderer()
	renderer.setBaseItemLabelFont(Font("Dialog", Font.BOLD, 16))
	renderer.setBaseItemLabelPaint(Color.WHITE)
	renderer.setItemLabelGenerator(myLabelGenerator())
#	renderer.setSeriesItemLabelPaint(1, Color.WHITE)
	renderer.setItemLabelsVisible(True)
	renderer.setBasePositiveItemLabelPosition(ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER))

```

On a side note, as i am still new to the JFreeChart stuff feel free to comment on anything in the code that you might think could be done better. I have just been finding and adapting examples.

---

<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:** [March 18, 2019, 6:10pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/4 "2019-03-18T18:10:52Z")

</div>

Hmm, setPadding might be from a newer version of JFreeChart than we’re bundling. Not sure why it’s not working - might well be a JFreeChart bug, to be honest.

Also, your code looks fine, although you can improve the readability a bit by organizing things to keep imports at the top, then class definitions, then the actual code:

```auto
from java.awt import Color, Font
from org.jfree.chart.labels import ItemLabelAnchor, ItemLabelPosition, StandardCategoryItemLabelGenerator
from org.jfree.chart.renderer.category import StandardBarPainter
from org.jfree.ui import RectangleInsets, TextAnchor

class myLabelGenerator(StandardCategoryItemLabelGenerator):
    def generateLabel(self, dataset, series, category):
        value = dataset.getValue(series,category)
        if value == 0:
            return None
        else:
            return str(int(value))

plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setBarPainter(StandardBarPainter())
renderer.setShadowVisible(0)
plot.setOutlinePaint(None)
plot.setInsets(RectangleInsets(0, 0, 0, 0))
renderer = plot.getRenderer()
renderer.setBaseItemLabelFont(Font("Dialog", Font.BOLD, 16))
renderer.setBaseItemLabelPaint(Color.WHITE)
renderer.setItemLabelGenerator(myLabelGenerator())
#	renderer.setSeriesItemLabelPaint(1, Color.WHITE)
renderer.setItemLabelsVisible(True)
renderer.setBasePositiveItemLabelPosition(ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER))

```

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 6:12pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/5 "2019-03-18T18:12:58Z")

</div>

yeah, once i get it working i will pretty up the code and comment it. also i just noticed that setPadding is not in the list of methods for the plot class. Would i need to convert it to a JFreeChart class?

---

<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:** [March 18, 2019, 6:14pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/6 "2019-03-18T18:14:59Z")

</div>

No - the setPadding method is on the root `chart` object (which is an instance of the `JFreeChart` class) - you run setPadding directly on the chart. The `setInsets` method is on the root `Plot` class, which is the root interface you get when you call `chart.getPlot()`. Try just `chart.setPadding(RectangleInsets(0,0,0,0))`.

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 6:18pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/7 "2019-03-18T18:18:29Z")

</div>

I tried that change with no luck. i also commented everything else out in case something was over ridding it. but that didnt work.

Here is the template if it helps.

[Jfreechart\_question.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f40c3a020d70984be4ad2cf093307bed910d96fa.proj) (7.0 KB)

---

<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:** [March 18, 2019, 6:25pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/8 "2019-03-18T18:25:35Z")

</div>

The classic Chart component is a subclass of the JFreeChart [ChartPanel](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartPanel.html). You might want to call the `self.setInsets()` method.

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 6:29pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/9 "2019-03-18T18:29:08Z")

</div>

Thanks for the suggestion. I tried adding,

```auto
self.setInsets(RectangleInsets(0, 0, 0, 0))

```

and

```auto
self.setPadding(RectangleInsets(0, 0, 0, 0))

```

but i get the same result as the chart.setPadding()

---

<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:** [March 18, 2019, 6:35pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/10 "2019-03-18T18:35:29Z")

</div>

Have you tried setting zero margins on your plot’s range (domain?) axis?

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 6:43pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/11 "2019-03-18T18:43:28Z")

</div>

Yes. the margins are both set to 0. which is how i got the chart to go from left to right properly. however, there arent any similar settings for the other axis to fill out the area in that direction.

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 7:51pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/12 "2019-03-18T19:51:01Z")

</div>

So i am going to work around the initial issue but i have found another.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/33a9c386e6aa7ffb4d651ee152ada2fc55f67f02.png)

I cant seem to get rid of the vertical dashed lines behind the bar. Is there an easy way to do this?

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [March 18, 2019, 8:14pm UTC](https://forum.inductiveautomation.com/t/chart-component-blank-space/23422/13 "2019-03-18T20:14:16Z")

</div>

Found out how to manually set this in the extension function.

```auto
	domainAxis = plot.getDomainAxis()
	domainAxis.setUpperMargin(0)
	domainAxis.setLowerMargin(0)

```

It worked. Thank you.
