echarts前端饼状图

1.去官网下载完整的echarts前端饼状图_第1张图片

然后将下载的js放到echarts前端饼状图_第2张图片

2.根据官网教程来写:

{% load static %}



    
    Title
    


其中{% load static %}和可以在这个网址看,注意static的文档:

这是在settings里面的

# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

3.views.py里的代码如下:

def get_singers_count(request):
    singers_count = {}
    for x in [chr(x).upper() for x in range(97, 123)]:
        if not cache.has_key('{}'.format(x)):
            url = 'http://127.0.0.1:8000/singers/?cname={}'.format(x)
            response = requests.get(url)
            json_str = response.text
            cache.set('{}'.format(x), json_str, 60*60)
        else:
            json_str = cache.get('{}'.format(x))
        json_obj = demjson.decode(json_str)
        total = int(json_obj['total'])
        singers_count[x] = total
    pie_data = [{'name': name, 'value': value} for name, value in singers_count.items()]
    return render(request, 'singer_count.html',{
        'zhu':{
            'xAxis': list(singers_count.keys()),
            'yAxis': list(singers_count.values()),
        },
        'bing':{
            'pie_data': pie_data
        }
    })

4.然后运行,去接口可以看到想要的图片了(仅供参考)

 

 

 

你可能感兴趣的:(kuwo接口)