highCharts Practise 1

结果


highCharts Practise 1_第1张图片
Result.png

代码



# coding: utf-8

# In[1]:

import pymongo
import charts


client = pymongo.MongoClient('localhost', 27017)
ganji = client['ganji']
item_info = ganji['item_info']


for i in item_info.find({},{'area':1,'_id':0}).limit(300):
    print(i)

areas = []
for i in item_info.find({},{'area':1,'_id':0}):
    if len(i['area']) > 1 and i['area'][1] != '':
        areas.append(i['area'][1])
    else:
        areas.append('不明')
# print(areas)
area_indexs = list(set(areas))
print(area_indexs)



post_times = []
for index in area_indexs:
    post_times.append(areas.count(index))
print(post_times)


def data_gen(chart_type):
    for area, times in zip(area_indexs,post_times):
        data = {
            'name':area,
            'data':[times],
            'type':chart_type
        }
        yield data

series = [data for data in data_gen('column')]
charts.plot(series, show='inline', options=dict(title=dict(text='Chars are Awesome!')))


总结


  • 主要是find用法,其他没什么难度。

  • 数据分析如下:

地区 帖子数量
朝阳 11608
海淀 8546
丰台 7019

你可能感兴趣的:(highCharts Practise 1)