Using Python, how can I update data programmatically for a Pygal chart?
The code below works fine as a static Stacked-Bar chart, but I can't figure out how to accommodate changing values.
Considerations/issues:
- My values, that I would like to update, come from a REST call as strings every five minutes.
- I haven't figured out how to update data for the Pygal chart, because inserting strings into the lists cause an error (shown below).
- I don't know how to insert a list of new integers into the "class" below.
- I'm showing only five data points for this example, but I might need to have as many as 100 data points eventually.
- Setting variables might work for a static number of elements but my elements will increase and decrease sporadically.
import pygal
line_chart = pygal.HorizontalStackedBar()
line_chart.title = 'Application Health'
line_chart.x_labels = ( "cluster05", "cluster04", "cluster03", "cluster02", "cluster01")
line_chart.add('Critical', [2, 5, 4, 1, None])
line_chart.add('Warning',[1, 7, 2, None, 2])
line_chart.add('OK', [25, 30, 19, 20, 25])
line_chart.render_to_file('test_StackedBar.svg')
The line type is the following class.
>>> type(line_chart.add('OK', [25, 30, 19, 20, 25]))
<class 'pygal.graph.horizontalstackedbar.HorizontalStackedBar'>
>>>
newData = "21, 55, 35, 82, 47, 70, 60"
line_chart.add('OK',[newData])
TypeError: unsupported operand type(s) for +: 'int' and 'str'
newData = "21, 55, 35, 82, 47, 70, 60"
y = list(newData)
line_chart.add('OK',[y])
line_chart.render_to_file('test_StackedBar.svg')
TypeError: unsupported operand type(s) for +: 'int' and 'list'