Browse Source

Migrando os graficos Pie da app diagnosticos para Chartjs

producao
Breno Teixeira 11 years ago
parent
commit
e0f522e366
  1. 114
      sigi/apps/diagnosticos/templates/diagnosticos/graficos.html
  2. 2
      sigiStatic/css/style.css

114
sigi/apps/diagnosticos/templates/diagnosticos/graficos.html

@ -3,66 +3,74 @@
{% block content_title %}<h1>Graficos dos Diagnósticos</h1>{% endblock %} {% block content_title %}<h1>Graficos dos Diagnósticos</h1>{% endblock %}
{% block extrahead %} {% block extrahead %}
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <link rel="stylesheet" href="{{ STATIC_URL }}css/style.css">
<script type="text/javascript" src="{{ STATIC_URL }}js/Chart.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}js/Chart.min.js"></script>
<script language=javascript> <script src="http://code.highcharts.com/highcharts.js"></script>
jQuery(document).ready(function () { <script language=javascript>
jQuery(document).ready(function () {
jQuery("form#categoria select").change(function () { jQuery("form#categoria select").change(function () {
jQuery("form#categoria").submit() jQuery("form#categoria").submit()
}); });
jQuery("#perguntas a").click(function(event){ jQuery("#perguntas a").click(function(event){
event.preventDefault(); event.preventDefault();
var id = jQuery(this).attr('id') var id = jQuery(this).attr('id')
var output_id = 'output_'+id var output_id = 'output_'+id
jQuery.ajax({ jQuery.ajax({
url: jQuery(this).attr('href'), url: jQuery(this).attr('href'),
success: function(data) { success: function(data) {
var ctx = document.getElementById(output_id).getContext("2d"); var ctx = document.getElementById(output_id).getContext("2d");
var myNewChart = new Chart(ctx).Pie(data); var myNewChart = new Chart(ctx).Pie(data);
$('#canvas_' + id).toggle(); var canvas = $("#canvas_" + id);
}, if (canvas.has('.pie-legend').length == 0) {
var legendHolder = document.createElement('div');
legendHolder.innerHTML = myNewChart.generateLegend();
canvas.append(legendHolder.firstChild);
}
error: function(errorSender, errorMsg) { $('#canvas_' + id).toggle();
jQuery(output_id).html(errorSender + ' ' + errorMsg); },
}
});
return false error: function(errorSender, errorMsg) {
}); jQuery(output_id).html(errorSender + ' ' + errorMsg);
}); }
</script> });
return false
});
});
</script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="content-main"> <div id="content-main">
<form id="categoria" action="." method="POST"> <form id="categoria" action="." method="POST">
{% csrf_token %} {% csrf_token %}
<select name="categoria"> <select name="categoria">
{% for categoria in categorias %} {% for categoria in categorias %}
<option value="{{ categoria.id }}" {% if categoria.id == sel_categoria %}selected="selected"{% endif %}>{{ categoria.nome }}</option> <option value="{{ categoria.id }}" {% if categoria.id == sel_categoria %}selected="selected"{% endif %}>{{ categoria.nome }}</option>
{% endfor %} {% endfor %}
</select> </select>
</form> </form>
<div id="perguntas"> <div id="perguntas">
<ul> <ul>
{% for pergunta in perguntas %} {% for pergunta in perguntas %}
<li style="list-style: none"> <li style="list-style: none">
{% if pergunta.datatype == 'many' or pergunta.datatype == 'one' %} {% if pergunta.datatype == 'many' or pergunta.datatype == 'one' %}
<a id="{{ pergunta.name }}" href="/diagnosticos/api/?id={{ pergunta.name }}"><p>{{ pergunta.title }}</p></a> <a id="{{ pergunta.name }}" href="/diagnosticos/api/?id={{ pergunta.name }}"><p>{{ pergunta.title }}</p></a>
<div id="canvas_{{ pergunta.name }}" style="display: none"> <div id="canvas_{{ pergunta.name }}" style="display: none">
<canvas id="output_{{ pergunta.name }}" width="220" height="220"></canvas> <canvas id="output_{{ pergunta.name }}" width="220" height="220"></canvas>
</div> </div>
{% else %} {% else %}
<p>{{ pergunta.title }}</p> <p>{{ pergunta.title }}</p>
{% endif %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

2
sigiStatic/css/style.css

@ -1,4 +1,4 @@
#canvas-holder-1, #canvas-holder-2 { div[id^=canvas] {
padding: 20px 20px 20px 20px; padding: 20px 20px 20px 20px;
min-height: 180px; min-height: 180px;
position: relative; position: relative;

Loading…
Cancel
Save