我在我的应用程序中使用了Checklist-Model指令,它返回的值如下所示:
#load the value in the list
k = ['smer', '1245', 'kdh', '7845', 'smer', '697', 'sns', '78', 'du', '421', 'smer', '632', 'ol', '4144', 'most-hid', '457', 'smer', '12', 'ol', '897', 'most-hid', '1234', 'kdh', '555', 'ol', '898', 'du', '7845']
#create a dictionary to hold the values
d = {}
for i in range(0,len(k),2):#iterate the length of the list, i will be every other index
key = k[i]
val = float(k[i+1])
if d.has_key(key): #if the key exists perform summation
d[key] += val
else: #if the key does not exist create it
d[key] = val
# a plotting library like matplot lib is required for the pie chart
import matplotlib.pyplot as plt
labels = d.keys()
values = d.values()
plt.pie(values, # data
labels=labels, # slice labels
autopct='%1.1f%%', # print the values inside the wedges
)
plt.show()
我的问题是如何使用此输出。我试图将它传递给JSON.parse,但这似乎导致了错误。
答案 0 :(得分:0)
我对获取输入的语法感到困惑。模型中的示例需要设置如下:
selectedSets.sets[0]
不
selectedSets[0]