# Avoid stretched bar chart

**URL:** <https://forum.inductiveautomation.com/t/avoid-stretched-bar-chart/67379>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 8, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/avoid-stretched-bar-chart/67379 "2022-12-08T12:55:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [December 8, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/avoid-stretched-bar-chart/67379/1 "2022-12-08T12:55:32Z")

</div>

Hi,  
I have a window with barchart as below in vision,

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/e/7e4072ad92a4b9c6f38b70ef644c9ad0a354fde2.png)  
I would like to avoid the elongated bar( I know it is elongates as it has only one column value)  
But is there a way to avoid this?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 8, 2022, 4:50pm UTC](https://forum.inductiveautomation.com/t/avoid-stretched-bar-chart/67379/2 "2022-12-08T16:50:54Z")

</div>

You could eliminate some of it by adding a blank row to your chart's dataset. Beyond that, I imagine that you could probably achieve this by manipulating your category margins with some sort of algorithm.

For example, if the catAxisUppermargin property were bound to a custom property (call it widthAdjustment). Then, the configureChart extension function could be used in the following way to manipulate this variable:

```auto
	maximumBars = 10.0
	minimumWidthAdjustment = .05
	maximumWithAdjustment = .7
	chartWidth = 1.0 - (float(self.data.rowCount)/maximumBars)
	if chartWidth < minimumWidthAdjustment:
		self.widthAdjustment = minimumWidthAdjustment
	elif chartWidth > maximumWithAdjustment:
		self.widthAdjustment = maximumWithAdjustment
	else:
		self.widthAdjustment = chartWidth

```

Note: this example algorithm is not something I've tested in any realistic way, it's just the first idea that popped into my head when I read this problem.

Edit:  
After pondering this for a few minutes, I imagine that it would be much better to apply this idea to a propertyChange event script, so it the chart isn't processing this calculation excessively:

```auto
if event.propertyName == "data":
	maximumBars = 10.0
	minimumWidthAdjustment = .05
	maximumWithAdjustment = .7
	chartWidth = 1.0 - (float(event.source.data.rowCount)/maximumBars)
	if chartWidth < minimumWidthAdjustment:
		event.source.widthAdjustment = minimumWidthAdjustment
	elif chartWidth > maximumWithAdjustment:
		event.source.widthAdjustment = maximumWithAdjustment
	else:
		event.source.widthAdjustment = chartWidth

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 8, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/avoid-stretched-bar-chart/67379/3 "2022-12-08T17:12:47Z")

</div>

Another idea: you could use the renderer's `.setMaximumBarWidth()` method in the configureChart extension function:

```auto
def configureChart(self, chart):
	chart.getPlot().getRenderer().setMaximumBarWidth(0.20)

```
