Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nvd3/bulletChart.py: 29%
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 bulletChart(TemplateMixin, NVD3Chart):
16 '''
17 A bullet chart is a variation of a bar graph
18 used to indicate the value of a single variable
19 in relation to a set of qualitative ranges. It is
20 inspired by a dashboard gauge or thermometer chart.
22 Python example:
24 from nvd3.bulletChart import bulletChart
25 chart = bulletChart.bulletChart(name=chart_name, height=100, width=500)
26 title = 'Revenue',
27 subtitle = 'US$, in thousands'
28 ranges = [150, 225, 300]
29 measures = [220, 270]
30 markers = [250]
31 chart.add_serie(
32 title=title,
33 subtitle=subtitle,
34 ranges=ranges,
35 measures=measures,
36 markers=markers)
37 chart.buildhtml()
38 print(chart.content)
40 JavaScript generated:
42 .. include:: ./examples/bulletChart.html
44 '''
45 CHART_FILENAME = './bulletchart.html'
46 template_chart_nvd3 = NVD3Chart.template_environment.get_template(
47 CHART_FILENAME)
49 def __init__(self, **kwargs):
50 super(bulletChart, self).__init__(**kwargs)
51 self.model = 'bulletChart'
53 height = kwargs.get('height', None)
54 width = kwargs.get('width', 200)
56 if height:
57 self.set_graph_height(height)
58 if width:
59 self.set_graph_width(width)
61 def add_serie(self, ranges, measures, title, subtitle, markers=None,
62 name=None, **kwargs):
63 if not name:
64 name = "Serie %d" % (self.serie_no)
65 if markers:
66 serie = [{
67 'title': title,
68 'subtitle': subtitle,
69 'ranges': ranges,
70 'measures': measures,
71 'markers': markers
72 }]
73 else:
74 serie = [{
75 'title': title,
76 'subtitle': subtitle,
77 'ranges': ranges,
78 'measures': measures,
79 }]
80 data_keyvalue = {'values': serie, 'key': name}
82 self.serie_no += 1
83 self.series.append(data_keyvalue)