1

I'm wondering if it's possible to combine two sets of data (made up of two lists each) into a pygal chart.

The code would look something like this:

new_chart = pygal.StackedBar()

# set 1
new_chart.add('1-1',[1,2,3,4])
new_chart.add('1-2',[4,3,2,1])

# set 2
new_chart.add('2-1',[9,8,7,6])
new_chart.add('2-2',[6,7,8,9])

new_chart.render()

But I would want the second set to be next to (not stacked on) the first set.

elPastor
  • 8,435
  • 11
  • 53
  • 81

1 Answers1

1

That kind of does the trick :

new_chart = pygal.StackedBar()

# set 1
new_chart.add('1-1',[1, 0, 2, 0, 3, 0, 4, 0])
new_chart.add('1-2',[4, 0, 3, 0, 2, 0, 1, 0])

# set 2
new_chart.add('2-1',[0, 9, 0, 8, 0, 7, 0, 6])
new_chart.add('2-2',[0, 6, 0, 7, 0, 8, 0, 9])

The output image

You can get a clearer image with additional zeros for empty spaces :

new_chart = pygal.StackedBar()
# set 1
new_chart.add('1-1',[1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0])
new_chart.add('1-2',[4, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0])

# set 2
new_chart.add('2-1',[0, 9, 0, 0, 8, 0, 0, 7, 0, 0, 6])
new_chart.add('2-2',[0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9])

Jacquot
  • 1,750
  • 15
  • 25
  • While this is a dirty fix, it sort of answers the question. The reality is that I don't think it's possible (in the current version of pygal), so this is probably the best possible option. Thank you. – elPastor May 12 '16 at 13:54