def create_pie(): pie = Pie('膠條良率', "數據", title_pos='center', width='100%') pie.add("", ["紅", ""], [25, 75], center=[10, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, ) pie.add("", ["橘", ""], [24, 76], center=[30, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left') pie.add("", ["黃", ""], [14, 86], center=[50, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["綠", ""], [11, 89], center=[70, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["藍", ""], [27, 73], center=[90, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center") pie.renderer = 'svg' return pie
def create_simple_pie(): pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center') pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, ) pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left') pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center") pie.renderer = 'svg' return pie
def create_pie(): film_datas = FilmGap.objects.all() spec = { 'gap0': [1, 1.5], 'gap1': [1.8, 2.3], 'gap2': [1.8, 2.3], 'gap3': [1.8, 2.3], 'gap4': [1.8, 2.3], 'gap5': [1, 1.5] } pie = Pie('貼合良率', "數據", title_pos='center', width='100%') style = Style() pie_style = style.add(label_pos="center", is_label_show=True, label_text_color=None) static = {} for i in range(0, 6): gap = f"gap{i}" lower, upper = spec.get(gap) if i == 0: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap0__gte=upper)|Q(gap0__lte=lower)) center = [20, 30] elif i == 1: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap1__gte=upper)|Q(gap1__lte=lower)) center = [40, 30] elif i == 2: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap2__gte=upper)|Q(gap2__lte=lower)) center = [60, 30] elif i == 3: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap3__gte=upper)|Q(gap3__lte=lower)) center = [80, 30] elif i == 4: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap4__gte=upper)|Q(gap4__lte=lower)) center = [20, 70] elif i == 5: fail_count = FilmGap.objects \ .annotate(num=Count(gap)) \ .filter(Q(gap5__gte=upper)|Q(gap5__lte=lower)) center = [40, 70] static.setdefault(gap, len(fail_count)) f = (static.get(gap) / len(film_datas)) * 100 p = 100 - f ration = [f"{f:.1f}", f"{p:.1f}"] if i == 1: pie.add(gap, [gap, ""], ration, center=center, radius=[20, 26], **pie_style, legend_pos='left') elif i == 5: pie.add(gap, [gap, ""], ration, center=center, radius=[20, 26], **pie_style, is_legend_show=True, legend_top="center") else: pie.add(gap, [gap, ""], ration, center=center, radius=[20, 26], **pie_style) pie.renderer = 'svg' return pie