piechart.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {# This template adds attributes unique
  2. to pieChart #}
  3. {% extends "content.html" %}
  4. {% block body %}
  5. data_{{ chart.name }}={{ chart.series_js|striptags }};
  6. nv.addGraph(function() {
  7. var chart = nv.models.{{ chart.model }}(){% if chart.use_interactive_guideline %}.useInteractiveGuideline(true){% endif %};
  8. chart.margin({top: {{ chart.margin_top }}, right: {{ chart.margin_right }}, bottom: {{ chart.margin_bottom }}, left: {{ chart.margin_left }}});
  9. var datum = data_{{ chart.name }}[0].values;
  10. {% if not chart.color_list and chart.color_category %}
  11. chart.color(d3.scale.{{ chart.color_category }}().range());
  12. {% endif %}
  13. chart.tooltip.contentGenerator(function(d, elem) {
  14. var x = String(d.data.label);
  15. var y = String(d.data.value);
  16. tooltip_str = '<center><b>'+x+'</b></center>' + y;
  17. return tooltip_str;
  18. });
  19. {# showLabels only supported in pieChart #}
  20. chart.showLabels({{chart.show_labels|lower}});
  21. {% if chart.donut %}
  22. chart.donut(true);
  23. chart.donutRatio({{ chart.donutRatio }});
  24. {% else %}
  25. chart.donut(false);
  26. {% endif %}
  27. chart.showLegend({{chart.show_legend|lower}});
  28. {# add custom chart attributes #}
  29. {% for attr, value in chart.chart_attr.items() %}
  30. {% if value is string and value.startswith(".") %}:
  31. chart.{{ attr }}{{ value }};
  32. {% else %}
  33. chart.{{ attr }}({{ value }});
  34. {% endif %}
  35. {% endfor %}
  36. {% if chart.resize %}
  37. nv.utils.windowResize(chart.update);
  38. {% endif %}
  39. {% if chart.color_list %}
  40. var mycolor = new Array();
  41. {% for color in chart.color_list %}
  42. mycolor[{{ loop.index - 1}}] = "{{ color }}";
  43. {% endfor %}
  44. {% endif %}
  45. chart
  46. .x(function(d) { return d.label })
  47. .y(function(d) { return d.value });
  48. {% if chart.width %}
  49. chart.width({{ chart.width }});
  50. {% endif %}
  51. {% if chart.height %}
  52. chart.height({{ chart.height }});
  53. {% endif %}
  54. {% if chart.color_list %}
  55. chart.color(mycolor);
  56. {% endif %}
  57. {% block rendering_opts %}
  58. {% if chart.no_data_message %}
  59. chart.noData('{{chart.no_data_message}}')
  60. {% endif %}
  61. {% if chart.show_controls == False %}
  62. chart.showControls(false);
  63. {% endif %}
  64. {% endblock rendering_opts %}
  65. {% block inject %}
  66. {{super()}}
  67. {% endblock inject %}
  68. {% block extras %}
  69. {# extra chart attributes #}
  70. {% if chart.extras %}
  71. {{ chart.extras }}
  72. {% endif %}
  73. {% endblock extras %}
  74. {% if chart.callback %}
  75. },{{ chart.callback }});
  76. {% endif %}
  77. {% block close %}
  78. {{ super() }}
  79. {% endblock close %}
  80. {% endblock body %}