Beispiel #1
0
    def get(self, request, question_id):
        print(request.session.get('HTTP_REFERER'))
        question = get_object_or_404(Question, pk=question_id)
        choices = Choice.objects.filter(question_id=question_id)
        print(question_id)
        choice_list = []
        for choice in choices:
            choice_list.append((choice.choice_text, choice.votes))

        pie_path = 'polls/render/%s_charts.html' % question_id
        if not os.path.exists(pie_path):
            pie = charts.Pie()
            pie.add(
                question.question_text,
                choice_list,
            )
            pie.render(pie_path)
        else:
            pie_mod_time = os.path.getmtime(pie_path)
            print(pie_mod_time)
            print(time.time())
            print(time.time() - pie_mod_time)
            if time.time() - pie_mod_time >= 60:
                pie = charts.Pie()
                pie.add(
                    question.question_text,
                    choice_list,
                )
                pie.render(pie_path)

        chart = open(pie_path).read()
        return HttpResponse(chart)
def get_viz(method, label, data):
    if method == 'bar':
        viz = charts.Bar()
        viz.add_xaxis(label)
        viz.add_yaxis('', data)
    elif method == 'pie':
        data = [list(d) for d in zip(label, data)]
        viz = charts.Pie()
        viz.add('', data)
    return viz
            money_ = None
    if re.search(strr, '-'):
        try:
            strr_1, strr_2 = strr.split('-')
            money_ = np.mean((float(strr_1.replace(',', '').strip('$')),
                              float(strr_2.replace(',', '').strip('$'))))
        except:
            money_ = None

    return money_


# 转化价格为浮点数
price = data_df['goods_price'].map(money_change)
price_bins = [0, 15, 20, 25, 30, 35, 40, 100]
bins_values = pd.cut(price, bins=price_bins).value_counts()
e_bin_list = [(str(price_bins[m]) + '-' + str(price_bins[m + 1]), n)
              for m, n in zip(range(len(price_bins)), bins_values.tolist())]

data_pie = (chas.Pie().add(
    "价格区间",
    e_bin_list,
    center=['50%', '50%'],
    radius=['30%', '75%'],
    rosetype='area',
    label_opts=opts.LabelOpts(is_show=True, formatter='价格区间{b}:共{c}个,占{d}%'),
).set_global_opts(legend_opts=opts.LegendOpts(is_show=True), ))
data_pie.render_notebook()

amazon_kline = (chas.Kline().add)
Beispiel #4
0
def create_pie( col_name, y_list):
    pie = charts.Pie()

    pie.add(col_name, y_list)
    pie.render("Main/Sources/pie.html")
Beispiel #5
0
line.add_yaxis(series_name='A',y_axis = y1)
line.render(r'D:\Python Spyder\数据可视化\My PyEcharts\折线图4.html')

#====================================================================

# 饼图

#构建饼图数据
x_data = ['直接访问','营销推广','博客推荐','搜索引擎']
y_data = [800,214,300,1100]
    # Pie 设置指定的格式
data_pair = list(zip(x_data,y_data))
print(data_pair)

# 画饼图
pie = pyec.Pie()
pie.add(series_name='推广渠道',data_pair=data_pair, 
        # 环形图
        radius=['40%','75'])
pie.render(r'D:\Python Spyder\数据可视化\My PyEcharts\环形图.html')

#====================================================================

# 撒点图

# 生成数据
import numpy as np
x = np.linspace(0,10,30)
y1 = np.sin(x)

scatter = pyec.Scatter()