Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nvd3/multiBarChart.py: 32%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
4"""
5Python-nvd3 is a Python wrapper for NVD3 graph library.
6NVD3 is an attempt to build re-usable charts and chart components
7for d3.js without taking away the power that d3.js gives you.
9Project location : https://github.com/areski/python-nvd3
10"""
12from .NVD3Chart import NVD3Chart, TemplateMixin
15class multiBarChart(TemplateMixin, NVD3Chart):
16 """
17 A multiple bar graph contains comparisons of two or more categories or bars.
18 One axis represents a quantity and the other axis identifies a specific feature
19 about the categories. Reading a multiple bar graph includes looking at extremes
20 (tallest/longest vs. shortest) in each grouping.
22 Python example::
24 from nvd3 import multiBarChart
25 chart = multiBarChart(width=500, height=400, x_axis_format=None)
26 xdata = ['one', 'two', 'three', 'four']
27 ydata1 = [6, 12, 9, 16]
28 ydata2 = [8, 14, 7, 11]
30 chart.add_serie(name="Serie 1", y=ydata1, x=xdata)
31 chart.add_serie(name="Serie 2", y=ydata2, x=xdata)
32 chart.buildhtml()
33 print(chart.content)
35 Javascript generated:
37 .. include:: ./examples/multiBarChart.html
39 """
41 CHART_FILENAME = "./multibarchart.html"
42 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME)
44 def __init__(self, **kwargs):
45 super(multiBarChart, self).__init__(**kwargs)
47 height = kwargs.get('height', 450)
48 width = kwargs.get('width', None)
50 if kwargs.get('x_is_date', False):
51 self.set_date_flag(True)
52 self.create_x_axis('xAxis',
53 format=kwargs.get('x_axis_format', '%d %b %Y'),
54 date=True)
55 self.set_custom_tooltip_flag(True)
56 else:
57 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format', '.2f'))
58 self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.2f'))
60 self.set_graph_height(height)
61 if width:
62 self.set_graph_width(width)