# Is it possible to create XY Stacked Bar Chart?

**URL:** <https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336>\
**Category:** Ignition\
**Created:** [November 13, 2014, 4:36pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336 "2014-11-13T16:36:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [November 13, 2014, 4:36pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336/1 "2014-11-13T16:36:45Z")

</div>

I want to create a stacked bar chart that uses time series data, i.e. the x-axis contains times.

I don’t believe I can do this with the Bar Chart component.

If I use the (Classic) Chart Component I can set the type to XY Bar Renderer.

This almost does what I want. However the bars are not stacked, they appear behind one another.

Here is an example using the classic chart (set to XY Bar Renderer):

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/97a0cbba693fba20bac898936728a85be0e25cc0.png)  

I know I can sort of achieve this using the standard Bar Chart but as per this example, there is no data between 10am and 9am the next day, so the graph shows a gap, which is exactly what I want. But had I supplied the same data into the standard Bar Chart then I wouldn’t have got the gap.

I hope this makes sense. Is there a way to achieve this?

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [November 18, 2014, 8:42am UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336/2 "2014-11-18T08:42:39Z")

</div>

Anyone?

Having tried to do this using the standard bar chart it is not ideal at all, particularly when you get data that spans over a few days. I can’t set my categories to be just hours, e.g. “08:00”, “09:00”, “10:00” etc because as soon as I get into the next day then any data at the same time gets grouped with data from the previous day, i.e. all the “08:00” data gets put together.

So I have to have my labels as “Tue 08:00”, “Tue 09:00” , … , “Wed 01:00”, “Wed 02:00” etc meaning the labels are getting long, so I rotate them to 90 degrees but it still displays every single one so it’s looking very cluttered and not very user friendly.

Plus as stated previously if I didn’t have any data for a particular hour it would just be missed, I wouldn’t automatically get a gap.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 18, 2014, 12:33pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336/3 "2014-11-18T12:33:25Z")

</div>

Hmm… for a purely visual effect you could add a dataset to the chart to hold the “stacked” data. Basically, you’d add to the previous values:

`if event.propertyName=='Data':
  dataIn=event.source.parent.getComponent('Chart').Data
  headers = list(dataIn.getColumnNames())
  pyData=system.dataset.toPyDataSet(dataIn)
  newData=[]
  for row in pyData:
    newRow=[row[0],row[1]]
    for col in range(2,len(row)):
      newRow.append(row[col]+newRow[col-1])
    newData.append(newRow)
  event.source.parent.getComponent('Chart').StackedBar=system.dataset.toDataSet(headers,newData)`

I say purely visual, because, of course, the subsequent values get changed.

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [November 19, 2014, 4:32pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-create-xy-stacked-bar-chart/9336/4 "2014-11-19T16:32:33Z")

</div>

Jordan - thanks that is an interesting idea, was completely confused by what you meant at first but then suddenly it clicked.
