Example #1
0
def make_image(data, filepath, title, labels, major_labels):
    custom_style = Style(background='#fff',
                         plot_background='transparent',
                         title_font_size=14,
                         guide_stroke_dasharray='1,0',
                         major_guide_stroke_dasharray='1,0',
                         foreground='rgba(0, 0, 0, .87)',
                         foreground_strong='rgba(0, 0, 0, .87)',
                         foreground_subtle='rgba(0, 0, 0, .87)',
                         stroke_opacity='1',
                         stroke_opacity_hover='1',
                         stroke_width=10,
                         stroke_width_hover=10,
                         opacity='1',
                         opacity_hover='1',
                         colors=('#C5D4B5BB', '#3D7930'))
    print(custom_style.to_dict())

    r = get_range(data)

    config = Config()
    config.interpolate = 'cubic'
    config.style = custom_style
    config.width = 400
    config.height = 225
    config.explicit_size = True
    config.margin_left = 0
    config.margin_right = 0
    config.margin_top = 10
    config.margin_bottom = 30
    config.show_minor_x_labels = False
    config.truncate_label = -1
    config.show_legend = False
    config.include_x_axis = True
    config.range = r
    config.show_dots = False

    chart = pygal.Line(config)
    chart.title = ("Throughput (%s, Mb/s)" % (title))
    chart.x_labels = labels
    chart.x_labels_major = major_labels
    chart.y_labels = [
        x for x in range(0, r[1] + 1, 100 if (r[1] > 550) else 50)
    ]
    chart.add(None, data, fill=True)
    chart.add(None, data)
    #with open(filepath, 'w') as output:
    #  output.write(chart.render())
    chart.render_to_png(filepath)
Example #2
0
 def pygal_line_plot(self, vars: list) -> None:
     """ build and save line plot in pygal
     :param vars: list of the y vars in the graph
     """
     if not self.data:
         self.no_data_message = Markup("""<p>No data available</p>""")
     else:
         # Pygal config
         config = Config()
         config.show_legend = True
         config.include_x_axis = False
         config.stroke_style = {'width': 7}
         config.dots_size = 8
         config.x_label_rotation = -45
         # init graph
         graph = pygal.Bar(config,
                           margin_top=10,
                           range=(1, 5),
                           style=self.pygal_line_style,
                           legend_at_bottom=True,
                           legend_box_size=20,
                           truncate_legend=-1)
         # init data
         revered_df = self.pandas_df.sort_values('date', ascending=True)
         dates = [x.strftime('%Y-%m-%d') for x in list(revered_df['date'])]
         graph.x_labels = dates
         print(graph.x_labels)
         for var in vars:
             print(var)
             data = list(revered_df[var])
             graph.add('{} lvl'.format(var), data)
         path = os.path.join(os.getcwd(),'health_tracker', 'static') if \
             os.getcwd().endswith('health_tracker') else \
             os.path.join(os.getcwd(),'health_tracker', 'health_tracker', 'static')
         graph.render_to_file(
             os.path.join(path, '{}_line_graph.svg'.format(self.name)))
Example #3
0
#	from pygal.style import LightSolarizedStyle

	# Create Config object
	from pygal import Config
	chartCfg = Config()
	chartCfg.show_legend = True
	chartCfg.human_readable = True
	chartCfg.pretty_print=True
	if bFilledLineChart: 
		chartCfg.fill = True
	else:
		chartCfg.fill = False
	chartCfg.x_scale = 1
	chartCfg.y_scale = 1
	chartCfg.x_label_rotation = 45
	chartCfg.include_x_axis = True
	chartCfg.show_dots=False
	if nMaxDataCount > 0: 
		chartCfg.show_minor_x_labels=False
		chartCfg.x_labels_major_count=nMaxDataCount
	chartCfg.js = [	'svg.jquery.js','pygal-tooltips.js' ] # Use script from local
#	chartCfg.style = LightSolarizedStyle
	chartCfg.print_values = False
	chartCfg.print_zeroes = True
	chartCfg.no_data_text = "All values are 0"
	if bLogarithmicChart: 
		chartCfg.logarithmic=True	# Makes chart Y-Axis data more readable

	# Create Linechart
	if bLineChart:
		myChart = pygal.Line(chartCfg)
Example #4
0
    from pygal.style import RotateStyle

    # Create Config object
    from pygal import Config
    chartCfg = Config()
    chartCfg.show_legend = True
    chartCfg.human_readable = True
    chartCfg.pretty_print = True
    if bFilledLineChart:
        chartCfg.fill = True
    else:
        chartCfg.fill = False
    chartCfg.x_scale = 1
    chartCfg.y_scale = 1
    chartCfg.x_label_rotation = 45
    chartCfg.include_x_axis = True
    chartCfg.show_dots = False
    if nMaxDataCount > 0:
        chartCfg.show_minor_x_labels = False
        chartCfg.x_labels_major_count = nMaxDataCount
    #chartCfg.style = DefaultStyle #LightSolarizedStyle
    chartCfg.style = RotateStyle('#FF0000')
    chartCfg.print_values = True  #False
    chartCfg.print_zeroes = True
    chartCfg.no_data_text = "All values are 0"
    if bLogarithmicChart:
        chartCfg.logarithmic = True  # Makes chart Y-Axis data more readable

    # remove first item if configured!
    if bDeltaIgnoreFirstValue:
        for iChartNum in range(3, len(aFields)):