pyecharts ,geo,

from pyecharts.charts import Bar, Pie, Page, Grid, Line, Geo
from pyecharts.faker import Faker
from pyecharts import options as opts
from pyecharts.globals import ChartType, SymbolType


# ok, 世界地图
def update(request):
    geo = Geo(init_opts=opts.InitOpts(bg_color='#38414E'))    # 整体背景颜色

    # ChartType:图标类型,SymbolType:标记点类型
    geo.add_schema(maptype='world',
                   itemstyle_opts=opts.ItemStyleOpts(color="#50556B", border_color="#111"), #修改地图本体颜色
                   # bounding_coords =  #坐标
                   # emphasis_itemstyle_opts=opts.ItemStyleOpts(area_color='black', color='blue', color0='blue', opacity=0),  #地图颜色,但是好像没效果.
                   # label_opts=opts.LabelOpts(color='blue')  #图标签的颜色
                   )
    geo.add("", [("Andorra", 10), ("China", 20), ("Aruba", 30), ("Belize", 40), ("Taiwan", 50), ("Cuba", 60), ("America", 70)],
            type_=ChartType.EFFECT_SCATTER,
            color='#6B96A0',  # 点颜色
            effect_opts=opts.EffectOpts(color='#6B96A0')   #光晕颜色
            )
    geo.add("GEO",
            [("China", "Andorra"),
             ("China", "Aruba"),
             ("China", "Belize"),
             ("China", "Taiwan"),
             ("China", "Cuba")],
            type_=ChartType.LINES,
            # is_polyline=True,       #去掉线尾的箭头
            effect_opts=opts.EffectOpts(symbol=SymbolType.RECT,  #样式
                                        scale=5,
                                        symbol_size=10,  #轨迹大小
                                        color="#489EC0",   #轨迹颜色
                                        period=0.8,   #出现的频率间隔,越小间隔越短
                                        # trail_length=1, #尾巴长度, 数字越大越长
                                        ),
            linestyle_opts=opts.LineStyleOpts(curve=0.2,
                                              width=0.3,
                                              color='#42515B',
                                              opacity=0     #设置透明
                                              ),
            is_large=True)

    # 不显示标签
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 设置图标标题,visualmap_opts=opts.VisualMapOpts()为左下角的视觉映射配置项
    geo.set_global_opts(
        # isualmap_opts=opts.VisualMapOpts(),
        # legend_opts=opts.LegendOpts(is_show=False),
        # visualmap_opts=opts.VisualMapOpts(range_opacity=0, is_show=False),
        # title_opts=opts.TitleOpts(title='geo lines'),
        )
    geo_json = geo.dump_options_with_quotes()
    return JsonResponse(json.loads(geo_json))

  

posted @ 2022-06-02 20:21  CrossPython  阅读(106)  评论(0编辑  收藏  举报