# "Grouped Bar and Line Chart in Perspective for Energy Monitoring"

**URL:** <https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 30, 2025, 9:49pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957 "2025-06-30T21:49:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandana.k](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chandana.k](https://forum.inductiveautomation.com/u/chandana.k)\
**Post date:** [June 30, 2025, 9:49pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957/1 "2025-06-30T21:49:35Z")

</div>

1. I’m trying to create a chart that shows both energy consumption and production using grouped bars, along with a trendline for energy over time—similar to the attached one. Is it possible to build something like this in Ignition, especially in Perspective?"  
 ![Screenshot 2025-06-30 190110](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4fc59a9bf7e369bd9a803f1ede73bf06fb799ef0.png)

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [June 30, 2025, 10:19pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957/2 "2025-06-30T22:19:21Z")

</div>

You can do that with an XY Chart. Set `render: column` and `stacked: true` for the bars:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7312ab267747339f4fd89afea03a16529fcfdf7d.png)

You have to calculate your own trend lines. I use a Python script to generate a linear regression for a given list of values:

```python
def linearRegressionOf(numList, allowNegativeValues=False):
	x = []
	y = []
	for i in range(len(numList)):
		x.append(i)
		y.append(numList[i])
	try:
		slope, yInt, rr = Math.linreg(x, y)
	except:
		slope, yInt, rr = [0, 0, 0]
	lr = []
	for i in range(len(numList)):
		val = slope * i + yInt
		if val < 0 and not allowNegativeValues:
			val = 0
		lr.append(val)
	return lr

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 30, 2025, 10:40pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957/3 "2025-06-30T22:40:03Z")

</div>

> [@chandana.k](#):
>
> a chart that shows both energy consumption and production using grouped bars

What exactly is the chart supposed to tell the reader? You're stacking cases on kWh! Surely a chart of energy per case produced would be more useful?

Tip: "KWh" is a kelvin-watt-hour. It should be "kWh".

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [September 19, 2025, 3:37pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957/4 "2025-09-19T15:37:57Z")

</div>

What is Math.linreg()? Is that another function that you created? It doesn’t exist in the standard Python math module.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 19, 2025, 3:44pm UTC](https://forum.inductiveautomation.com/t/grouped-bar-and-line-chart-in-perspective-for-energy-monitoring/107957/5 "2025-09-19T15:44:50Z")

</div>

Yes, though I didn't create it, and don't recall where/how I found it (might have been from [this post](https://forum.inductiveautomation.com/t/inventory-prediction-manager/93439/11)):

```python
def linreg(X, Y):
    if len(X) != len(Y): raise ValueError, 'unequal length'
    N = len(X)
    Sx = Sy = Sxx = Syy = Sxy = 0.0
    for x, y in map(None, X, Y):
        Sx = Sx + x
        Sy = Sy + y
        Sxx = Sxx + x*x
        Syy = Syy + y*y
        Sxy = Sxy + x*y
    det = Sxx * N - Sx * Sx
    a, b = (Sxy * N - Sy * Sx)/det, (Sxx * Sy - Sx * Sxy)/det
    meanerror = residual = float(0.0)
    for x, y in map(None, X, Y):
        meanerror = meanerror + (y - Sy/N)**2
        residual = residual + (y - a * x - b)**2
    RR = 1 - residual/meanerror
    ss = residual / (N-2)
    Var_a, Var_b = ss * N / det, ss * Sxx / det
    return a, b, RR

```
