예제 #1
0
def index(request):
    # data = '我的名字叫蒋文华'
    # return render(request, 'index.html', {'data': data})

    if request.method == 'POST':
        form = SqlForm(request.POST)
        if form.is_valid():
            sql = form.cleaned_data['sql']
            title = form.cleaned_data['title']
            x = form.cleaned_data['x_label']
            y = form.cleaned_data['y_label']

            x1, y1 = conn('wboss', 'postgres', '', '10.0.0.141', '5432', sql)

            # y1 = [2, 3, 4, 5, 6]
            # x1 = ['Nov', 'Dec', 'Jan', 'Feb', 'marth']
            chart = Echart(title, '')
            chart.use(Bar(y, y1))
            chart.use(Legend(['GDP']))
            chart.use(Axis('category', 'bottom', data=x1, name=x))
            chart.use(Tooltip())

            chart.plot()
            # return HttpResponse(res)
    else:
        form = SqlForm()
    return render(request, 'index.html', {'form': form})
def draw(datas, **kwargs):

    title = '缺少标题'
    if 'title' in kwargs:
        title = kwargs['title']
    subtext = ''
    if 'subtext' in kwargs:
        subtext = kwargs['subtext']
    # 绘图对象,包含标题设置
    chart = Echart(title, subtext)

    # 绘图数据
    tags = list()
    for data in datas:
        tags.append(data)
        chart.use(Line(data, datas[data]))

    x_name = ''
    y_name = ''
    x_line = []
    if 'label' in kwargs:
        x_name = kwargs['label'][0]
        y_name = kwargs['label'][1]
        x_line = kwargs['label'][2]
    # x轴
    chart.use(Axis('category', 'bottom', x_name, data=x_line))
    # y轴
    chart.use(Axis('value', 'left', y_name))

    # 标签
    t_top = 60
    if 'top' in kwargs:
        t_top = kwargs['top']
    chart.use(Legend(tags, top=t_top))
    # 添加工具栏
    chart.use(Toolbox())
    # 设置绘图区域的位置,默认上留120,下留100
    chart.use(Grid())
    # tooltip
    chart.use(Tooltip())
    # 打开浏览器并绘图
    # chart.plot()
    return chart.get_opt()
예제 #3
0
def test_tooltip_assert():
    tooltip = Tooltip('nil')
예제 #4
0
def test_tooltip():
    chart = Echart('Tooltip', 'Tooltip for echarts')
    chart.use(Tooltip('axis', show=True))

    assert chart.json['tooltip']['trigger'] == 'axis'
    assert chart.json['tooltip']['show'] == True