multiBarHorizontalChart.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Python-nvd3 is a Python wrapper for NVD3 graph library.
  5. NVD3 is an attempt to build re-usable charts and chart components
  6. for d3.js without taking away the power that d3.js gives you.
  7. Project location : https://github.com/areski/python-nvd3
  8. """
  9. from .NVD3Chart import NVD3Chart, TemplateMixin
  10. class multiBarHorizontalChart(TemplateMixin, NVD3Chart):
  11. """
  12. A multiple horizontal bar graph contains comparisons of two or more categories or bars.
  13. Python example::
  14. from nvd3 import multiBarHorizontalChart
  15. chart = multiBarHorizontalChart(name='multiBarHorizontalChart', height=400, width=400)
  16. xdata = [-14, -7, 7, 14]
  17. ydata = [-6, 5, -1, 9]
  18. y2data = [-23, -6, -32, 9]
  19. extra_serie = {"tooltip": {"y_start": "", "y_end": " balls"}}
  20. chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie)
  21. extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}}
  22. chart.add_serie(name="Serie 2", y=y2data, x=xdata, extra=extra_serie)
  23. chart.buildhtml()
  24. print(chart.content)
  25. Javascript generated:
  26. .. include:: ./examples/multiBarHorizontalChart.html
  27. """
  28. CHART_FILENAME = "./multibarcharthorizontal.html"
  29. template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME)
  30. def __init__(self, **kwargs):
  31. super(multiBarHorizontalChart, self).__init__(**kwargs)
  32. height = kwargs.get('height', 450)
  33. width = kwargs.get('width', None)
  34. self.create_x_axis('xAxis', format=kwargs.get('x_axis_format', '.2f'))
  35. self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.2f'))
  36. self.set_graph_height(height)
  37. if width:
  38. self.set_graph_width(width)