瀏覽代碼

changing country bar chart to pie chart

solr_update
Simon Bowie 3 年之前
父節點
當前提交
82ecc08144
共有 2 個檔案被更改,包括 8 行新增19 行删除
  1. +7
    -2
      web/app/data.py
  2. +1
    -17
      web/app/templates/data.html

+ 7
- 2
web/app/data.py 查看文件

country_labels = [] country_labels = []
country_numbers = [] country_numbers = []
country_dataset = [] country_dataset = []
background_colours = []
for i in range(0, len(country_data)): for i in range(0, len(country_data)):
if i % 2: if i % 2:
country_numbers.append(country_data[i]) country_numbers.append(country_data[i])
random_colour = "#" + "%06x" % random.randint(0, 0xFFFFFF)
country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": random_colour}
x = 0
while x <= len(country_data):
random_colour = "#" + "%06x" % random.randint(0, 0xFFFFFF)
background_colours.append(random_colour)
x += 1
country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": background_colours}
else: else:
country = pycountry.countries.get(alpha_2=country_data[i]) country = pycountry.countries.get(alpha_2=country_data[i])
if country is not None: if country is not None:

+ 1
- 17
web/app/templates/data.html 查看文件

}; };


var config = { var config = {
type: 'bar',
type: 'pie',
data: data, data: data,
options: { options: {
plugins: { plugins: {
}, },
}, },
responsive: true, responsive: true,
scales: {
x: {
title: {
display: true,
text: 'country'
},
stacked: true,
},
y: {
title: {
display: true,
text: 'number of records'
},
stacked: true
}
}
} }
}; };



Loading…
取消
儲存