var data = ["10", "20", "30", "40"];
{{ drawPie(data) }};
from pylab import *print "Within ui_methods"def drawPie(self, fracs):
figure(3, figsize=(4,4))
axes([0.1, 0.1, 0.8, 0.8]) mycolors=['red', 'blue', 'green', 'brown']
mylabels=['Red', 'Blue', 'Green', 'Brown']
#fracs=[40, 30, 20, 10]
print ("fracs:", fracs)
pie(fracs,labels=mylabels,colors=mycolors) savefig('pie')
print ("File saved") return
<!DOCTYPE html>
<html>
<head>
<title>Pie Chart</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script type="text/javascript">
var ws = new WebSocket("ws://10.151.170.5:8888/websocket");
ws.onmessage = function(evt){
x = document.createElement("p");
document.getElementById("button").appendChild(x);
} function DispatchText(){
if (document.getElementById("day1").checked) {
var data = ["10", "20", "30", "40"];
{{ drawPie(["10", "20", "30", "40"]) }};
}
}
</script> </head>
<body>
<form>
<input type="radio" id="day1" name="day" value="Monday">Monday<br>
<input type="radio" id="day2" name="day" value="Tuesday">Tuesday<br>
</form>
<button onclick= "DispatchText()" action="javascript:void(0);">Vote</button>
</body>
</html>
{% set data= ["10", "20", "30", "40"] %};
{{ drawPie(data)}};function DispatchText(){
if (document.getElementById("day1").checked) {
var data = ["10", "20", "30", "40"];
$.ajax({
url: "http://your.web.domain.com/callDrawPie",
data: JSON.stringify(data),
dataType: 'json',
success: function() {
console.log("Server handled request successfully.");
// do whatever client side work you need to do here.
}
});
{{ drawPie(["10", "20", "30", "40"]) }};
}
}