예제 #1
0
    def pie_two_html(self, chart_id, title, sub_title1, sub_title2, key1, key2, val1, val2):
        # 实例化饼状图
        pie = Pie(init_opts=opts.InitOpts(width="100%", height="300px"))
        pie.set_global_opts(
            title_opts=opts.TitleOpts(
                title="{}-{}".format(self.dt, title),
                title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=14),
                pos_left="center"
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        )
        pie.chart_id = chart_id
        # print("key1: %s" % key1)
        # print("val1: %s" % val1)
        pie.add(
            sub_title1,
            [list(z1) for z1 in zip(key1, val1)],
            center=[300, 160],
            radius=[30, 75],
        )
        pie.add(
            sub_title2,
            [list(z2) for z2 in zip(key2, val2)],
            center=[1100, 160],
            radius=[30, 75],
        )

        return pie.render_embed()
예제 #2
0
 def pie_two_html(self, chart_id, title, sub_title1, sub_title2, key1, key2,
                  val1, val2):
     # 实例化饼状图
     pie = Pie(self.init_opts)
     # 绑定id
     pie.chart_id = chart_id
     # 绑定属性和值
     pie.add(sub_title1, [list(v) for v in zip(key1, val1)],
             center=["25%", "50%"],
             radius=["30%", "75%"],
             rosetype="area",
             label_opts=options.LabelOpts(is_show=True))
     pie.add(sub_title2, [list(v) for v in zip(key2, val2)],
             center=["75%", "50%"],
             radius=["30%", "75%"],
             rosetype="area",
             label_opts=options.LabelOpts(is_show=True))
     # 全局参数
     pie.set_global_opts(
         title_opts=self.title_opts(title),  # 标题选项
         legend_opts=options.LegendOpts(is_show=False),  # 不显示图例组件
     )
     # 返回图表html代码
     return pie.render_embed()