2017-03-09 110 views
0

我正在嘗試在pygal中使用api創建條形圖,並根據星星圖表顯示最流行的項目。我在下面發佈了我的代碼,但我無法弄清楚爲什麼我的圖表一直在說「無數據」?有什麼建議麼?謝謝!Pygal條形圖顯示「無數據」

import requests 
import pygal 
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS 

url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' 
r = requests.get(url) 
print("Status code:", r.status_code) 

response_dict = r.json() 
print('Total repositories:', response_dict['total_count']) 

repo_dicts = response_dict['items'] 


names,stars = [],[] 
for repo_dict in repo_dicts: 
    names.append(repo_dict['name']) 
    stars.append(repo_dict['stargazers_count']) 

my_style = LS('#333366',base_style=LCS) 
chart = pygal.Bar(style=my_style,x_label_rotation=45,show_legend=False) 
chart.title = 'Most Starred Python Projects on GitHub' 
chart.x_labels = names 
chart.add = ('',stars) 
chart.render_to_file('python_repos.svg') 

回答

1

您的代碼的倒數第二行,chart.add =(「」,星級)不應該有一個「=」等號存在,應該chart.add(「」,星)那麼代碼應該工作! :)