Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nvd3/multiChart.py: 25%

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

24 statements  

1#!/usr/bin/python 

2# -*- coding: utf-8 -*- 

3 

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. 

8 

9Project location : https://github.com/areski/python-nvd3 

10""" 

11 

12from .NVD3Chart import NVD3Chart, TemplateMixin 

13 

14 

15class multiChart(TemplateMixin, NVD3Chart): 

16 

17 """ 

18 A multiChart is a type of chart which combines several plots of the same or different types. 

19 

20 Python example:: 

21 

22 from nvd3 import multiChart 

23 chart_name = "multiChart" 

24 chart = multiChart(name=chart_name, x_is_date=False, x_axis_format="AM_PM") 

25 

26 xdata = [1,2,3,4,5,6] 

27 ydata = [115.5,160.5,108,145.5,84,70.5] 

28 ydata2 = [48624,42944,43439,24194,38440,31651] 

29 

30 kwargs1 = {'color': 'black'} 

31 kwargs2 = {'color': 'red'} 

32 extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}} 

33 chart.add_serie(y=ydata, x=xdata, type='line', yaxis=1, name='visits', extra=extra_serie, **kwargs1) 

34 extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} 

35 chart.add_serie(y=ydata2, x=xdata, type='bar', yaxis=2,name='spend', extra=extra_serie, **kwargs2) 

36 chart.buildhtml() 

37 print(chart.content) 

38 

39 

40 Javascript rendered to: 

41 

42 .. include:: ./examples/multiChart.html 

43 

44 See the source code of this page, to see the underlying javascript. 

45 """ 

46 CHART_FILENAME = "./multichart.html" 

47 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME) 

48 

49 def __init__(self, **kwargs): 

50 super(multiChart, self).__init__(**kwargs) 

51 self.model = 'multiChart' 

52 

53 height = kwargs.get('height', 450) 

54 width = kwargs.get('width', None) 

55 

56 if kwargs.get('x_is_date', False): 

57 self.set_date_flag(True) 

58 self.create_x_axis('xAxis', 

59 format=kwargs.get('x_axis_format', '%d %b %Y'), 

60 date=True) 

61 self.set_custom_tooltip_flag(True) 

62 else: 

63 if kwargs.get('x_axis_format') == 'AM_PM': 

64 self.x_axis_format = format = 'AM_PM' 

65 else: 

66 format = kwargs.get('x_axis_format', 'r') 

67 self.create_x_axis('xAxis', format=format, 

68 custom_format=kwargs.get('x_custom_format', 

69 False)) 

70 self.create_y_axis( 

71 'yAxis1', 

72 format=kwargs.get('y1_axis_format', '.02f'), 

73 custom_format=kwargs.get('y1_custom_format', False)) 

74 

75 self.create_y_axis( 

76 'yAxis2', 

77 format=kwargs.get('y2_axis_format', '.02f'), 

78 custom_format=kwargs.get('y2_custom_format', False)) 

79 

80 # must have a specified height, otherwise it superimposes both chars 

81 self.set_graph_height(height) 

82 if width: 

83 self.set_graph_width(width)