view.py部分代码

    1. x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"]
    2. y_data = [335, 310, 274, 235, 400]
    3. data_pair = [list(z) for z in zip(x_data, y_data)]
    4. data_pair.sort(key=lambda x: x[1])
    5. p = (Pie(init_opts=opts.InitOpts(width="1600px", height="800px", bg_color="#2c343c"))
    6. .add(
    7. series_name="访问来源",
    8. data_pair=data_pair,
    9. rosetype="radius",
    10. radius="55%",
    11. center=["50%", "50%"],
    12. label_opts=opts.LabelOpts(is_show=False, position="center"),
    13. )
    14. .set_global_opts(
    15. title_opts=opts.TitleOpts(
    16. title="Customized Pie",
    17. pos_left="center",
    18. pos_top="20",
    19. title_textstyle_opts=opts.TextStyleOpts(color="#fff"),
    20. ),
    21. legend_opts=opts.LegendOpts(is_show=False),
    22. )
    23. .set_series_opts(
    24. tooltip_opts=opts.TooltipOpts(
    25. trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
    26. ),
    27. label_opts=opts.LabelOpts(color="rgba(255, 255, 255, 0.3)"),
    28. )
    29. )
    30. return render(request, 'chart.html', {"the_button": the_button, "p": p.render_embed()})

    html

    1. <view>{{p|safe}}</view>