Exemple #1
0
def liquid(request):
    liq = Plot('Liquid')

    liq.set_options({
        'percent': 0.25,
    })

    liq.render('liquid.html')
    return HttpResponse(liq.render_html())
Exemple #2
0
def column(request):
    col = Plot('Column')

    # data = get('https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/column.json')
    data = get(
        'https://gw.alipayobjects.com/os/antfincdn/8elHX%26irfq/stack-column-data.json'
    )
    # data = get('https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/grouping-column-data.json')

    col.set_options({
        'data': data,
        'xField': 'year',
        'yField': 'value',
        # 'isGroup': True,    # 分组
        'isStack': True,  # 堆叠
        'seriesField': 'type',
        'label': {
            'position':
            'middle',
            'layout': [
                # 柱形图数据标签位置自动调整
                {
                    'type': 'interval-adjust-position'
                },
                # 数据标签防遮挡
                {
                    'type': 'interval-hide-overlap'
                },
                # 数据标签文颜色自动调整
                {
                    'type': 'adjust-color'
                },
            ]
        },
        # # 设置颜色
        # 'color': ['#1ca9e6', '#f88c24'],
        # # 设置间距
        # 'marginRatio': 0.1,
        # # 指定柱子的最大宽度
        # 'maxColumnWidth': 20,
        # # 指定柱子的最小宽度
        # 'minColumnWidth': 20,
        # # 指定柱子的圆角
        # 'columnStyle': {
        #     'radius': [20, 20, 0, 0]
        # },
        # # 设置柱子的背景样式
        # 'columnBackground': {
        #     'style': {
        #         'fill': 'rgba(0,0,0,0.1)'
        #     }
        # }
    })

    col.render("stack-column.html")
    return HttpResponse(col.render_html())
Exemple #3
0
def waterfall(request):
    water_f = Plot('Waterfall')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/waterfall.json'
    )

    water_f.set_options({'data': data, 'xField': 'type', 'yField': 'money'})

    water_f.render('waterfall.html')
    return HttpResponse(water_f.render_html())
Exemple #4
0
def gauge(request):
    instrument = Plot('Gauge')

    instrument.set_options({
        # 设置仪表盘展示类型
        'innerRadius': 0.8,
        'type': 'meter',
        'meter': {
            'steps': 50,
            'stepRatio': 0.7,
        },
        'percent': 0.5,
        # 圆弧里圆心距离
        'radius': 0.75,
        # 自定义辅助圆弧的样式
        'range': {
            'ticks': [0, 1],
            # 'ticks': [0, 1 / 3, 2 / 3, 1],
            'color': ['l(0) 0:#F4664A 0.5:#FAAD14 1:#30BF78'],
            # 'color': ['#F4664A', '#FAAD14', '#30BF78'],
            # 'color': '#30BF78',
            'width': 32,
        },
        # 自定义指示器的样式
        'indicator': {
            'pointer': {
                'style': {
                    'stroke': '#FAAD14',
                },
            },
            'pin': {
                'style': {
                    'stroke': '#30BF78',
                }
            }
        },
        'statistic': {
            'content': {
                'style': {
                    'fontSize': '36px',
                    'lineHeight': '36px',
                },
            },
        },
        # 线端为圆弧
        # 'gaugeStyle': {
        #     'lineCap': 'round',
        # }
    })

    instrument.render("area.html")
    return HttpResponse(instrument.render_html())
Exemple #5
0
def histogram(request):

    his = Plot('Histogram ')
    data = get(
        'https://gw.alipayobjects.com/os/antfincdn/RoliHq%2453S/histogram.json'
    )

    his.set_options({
        'data': data,
        'binField': 'value',
        'binWidth': 2,
    })

    his.render('histogram.html')
    return HttpResponse(his.render_html())
Exemple #6
0
def area(request):
    are = Plot('Area')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/area.json'
    )

    are.set_options({
        'data': data,
        'xField': 'timePeriod',
        'yField': 'value',
        'xAxis': {
            'range': [0, 1],
        },
    })

    are.render("area.html")
    return HttpResponse(are.render_html())
Exemple #7
0
def pie(request):
    p = Plot('Pie')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/line-data.json'
    )
    import math
    p.set_options({
        'data': data,
        'radius': 1,
        'appendPadding': 10,
        'angleField': 'value',
        'colorField': 'year',
        # 设置环图
        'innerRadius': 0.6,
        # 设置扇形图
        # 'startAngle': math.pi,
        # 'endAngle': math.pi * 1.5,
        'label': {
            'type': 'inner',
            'offset': '-50%',
            'content': '{value}',
            'style': {
                'textAlign': 'center',
                'fontSize': 14,
            },
        },
        'statistic': {
            'title': True,
            'content': {
                'style': {
                    'whiteSpace': 'pre-wrap',
                    'overflow': 'hidden',
                    'textOverflow': 'ellipsis',
                },
            },
        },
        'pieStyle': {
            'lineWidth': 4,
        },
    })

    p.render('pie.html')
    return HttpResponse(p.render_html())
Exemple #8
0
def bar(request):
    row = Plot('Bar')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/line-data.json'
    )

    row.set_options({
        'data': data,
        'xField': 'value',
        'yField': 'year',
        'seriesField': 'year',
        'legend': {
            'position': 'top-left',
        },
    })

    row.render("bar.html")
    return HttpResponse(row.render_html())
Exemple #9
0
def index(request):
    line = Plot('Line')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/line.json'
    )

    line.set_options({
        'data': data,
        'xField': 'Date',
        'yField': 'scales',
        'smooth': True,
        # stepType: 'vh' // 可选项:hv | vh | hvh | vhv
        'xAxis': {
            # 'type': 'timeCat'
            'tickCount': 5,
        },
    })
    line.render('graph.html')
    return HttpResponse(line.render_html())
Exemple #10
0
def radar(request):
    rad = Plot('Radar')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/radar.json'
    )

    rad.set_options({
        'data': data,
        'xField': 'item',
        'yField': 'score',
        'seriesField': 'user',
        'meta': {
            'score': {
                'alias': '分数',
                'min': 0,
                'max': 80,
            },
        },
        'xAxis': {
            'line': 'null',
            'tickLine': 'null',
            'grid': {
                'line': {
                    'style': {
                        'lineDash': 'null',
                    },
                },
            },
        },
        # 开启面积
        'area': {},
        # 开启辅助点
        'point': {
            'size': 2,
        },
    })

    rad.render('radar.html')
    return HttpResponse(rad.render_html())
Exemple #11
0
from pyg2plot import Plot

gauge = Plot("Gauge")

gauge.set_options({
    "appendPadding": 32,
    "percent": 0.75,
    "range": {
        "ticks": [0, 1 / 3, 2 / 3, 1],
        "color": ["#F4664A", "#FAAD14", "#30BF78"],
    },
    "indicator": {
        "pointer": {
            "style": {
                "stroke": "#D0D0D0",
            },
        },
        "pin": {
            "style": {
                "stroke": "#D0D0D0",
            },
        },
    },
    "statistic": {
        "content": {
            "style": {
                "fontSize": "36px",
                "lineHeight": "36px",
            },
        },
    },
Exemple #12
0
    },
    {
        "type": "分类四",
        "value": 15
    },
    {
        "type": "分类五",
        "value": 10
    },
    {
        "type": "其他",
        "value": 5
    },
]

pie = Plot("Pie")

pie.set_options({
    "appendPadding": 32,
    "data": data,
    "angleField": "value",
    "colorField": "type",
    "radius": 0.8,
    "label": {
        "type": "outer",
    },
    "interactions": [{
        "type": "element-active"
    }],
})
from pyg2plot import Plot
from pywebio.output import put_html


liquid = Plot("Liquid")

liquid.set_options({
  "appendPadding": 32,
  "percent": 0.25,
  "outline": {
    "border": 4,
    "distance": 4,
  },
  "wave": {
    "length": 128,
  },
})

put_html(liquid.render_notebook())
Exemple #14
0
    },
    {
        "year": '2016',
        "value": 59.0
    },
    {
        "year": '2017',
        "value": 72.2
    },
    {
        "year": '2018',
        "value": 76.3
    },
]

line_admission = Plot("Line")

line_admission.set_options({
    "appendPadding": 32,
    "data": data_admission,
    "xField": "year",
    "yField": "value",
    "label": {},
    "smooth": True,
    "lineStyle": {
        "lineWidth": 3,
    },
    "point": {
        "size": 5,
        "shape": 'diamond',
        "style": {
Exemple #15
0
  { "x": 98, "y": 5, "size": 89, "genre": "male" },
  { "x": 51, "y": 50, "size": 73, "genre": "male" },
  { "x": 41, "y": 22, "size": 14, "genre": "male" },
  { "x": 58, "y": 24, "size": 20, "genre": "male" },
  { "x": 78, "y": 37, "size": 34, "genre": "male" },
  { "x": 55, "y": 56, "size": 53, "genre": "male" },
  { "x": 18, "y": 45, "size": 70, "genre": "male" },
  { "x": 42, "y": 44, "size": 28, "genre": "male" },
  { "x": 3, "y": 52, "size": 59, "genre": "male" },
  { "x": 31, "y": 18, "size": 97, "genre": "male" },
  { "x": 79, "y": 91, "size": 63, "genre": "male" },
  { "x": 93, "y": 23, "size": 23, "genre": "male" },
  { "x": 44, "y": 83, "size": 22, "genre": "male" }
]

scatter = Plot("Scatter")

scatter.set_options({
  "appendPadding": 32,
  "data": data,
  "xField": "x",
  "yField": "y",
  "colorField": "genre",
  "color": [
    "r(0.4, 0.3, 0.7) 0:rgba(255,255,255,0.5) 1:#5B8FF9",
    "r(0.4, 0.4, 0.7) 0:rgba(255,255,255,0.5) 1:#61DDAA",
  ],
  "sizeField": "size",
  "size": [5, 20],
  "shape": "circle",
  "yAxis": {
Exemple #16
0
# -*- coding: UTF-8 -*-
'''
Date: 2021-04-22 22:49:56
'''
from pyg2plot import Plot

column0 = Plot("Column")

column0.render_notebook()
Exemple #17
0
    {
        "year": "1952 年",
        "value": 52
    },
    {
        "year": "1956 年",
        "value": 61
    },
    {
        "year": "1957 年",
        "value": 145
    },
    {
        "year": "1958 年",
        "value": 48
    },
]

bar = Plot("Bar")

bar.set_options({
    "appendPadding": 32,
    "data": data,
    "xField": "value",
    "yField": "year",
    "seriesField": "year",
    "legend": False
})

bar.render("bar.html")
Exemple #18
0
    "date": 2014,
    "value": 5382.9
}, {
    "country": "亚太地区",
    "date": 2015,
    "value": 5472.4
}, {
    "country": "亚太地区",
    "date": 2016,
    "value": 5585.5
}, {
    "country": "亚太地区",
    "date": 2017,
    "value": 5743.6
}]

area = Plot("Area")

area.set_options({
    "appendPadding": 32,
    "data": data,
    "xField": "date",
    "yField": "value",
    "seriesField": 'country',
    "legend": {
        "position": "top"
    }
})

area.render("area.html")
Exemple #19
0
    },
    {
        "year": '1997',
        "value": 7
    },
    {
        "year": '1998',
        "value": 9
    },
    {
        "year": '1999',
        "value": 13
    },
]

line = Plot("Line")

line.set_options({
    "appendPadding": 32,
    "data": data,
    "xField": "year",
    "yField": "value",
    "label": {},
    "smooth": True,
    "lineStyle": {
        "lineWidth": 3,
    },
    "point": {
        "size": 5,
        "shape": 'diamond',
        "style": {
Exemple #20
0
from pyg2plot import Plot

line = Plot("Line")

line.set_options({
    "data": [
        {
            "year": "1991",
            "value": 3
        },
        {
            "year": "1992",
            "value": 4
        },
        {
            "year": "1993",
            "value": 3.5
        },
        {
            "year": "1994",
            "value": 5
        },
        {
            "year": "1995",
            "value": 4.9
        },
        {
            "year": "1996",
            "value": 6
        },
        {
Exemple #21
0
  { "time": "2019-05", "count": 400, "name": "a" },
  { "time": "2019-06", "count": 380, "name": "a" },
  { "time": "2019-07", "count": 220, "name": "a" },
  { "time": "2019-03", "count": 750, "name": "b" },
  { "time": "2019-04", "count": 650, "name": "b" },
  { "time": "2019-05", "count": 450, "name": "b" },
  { "time": "2019-06", "count": 400, "name": "b" },
  { "time": "2019-07", "count": 320, "name": "b" },
  { "time": "2019-03", "count": 900, "name": "c" },
  { "time": "2019-04", "count": 600, "name": "c" },
  { "time": "2019-05", "count": 450, "name": "c" },
  { "time": "2019-06", "count": 300, "name": "c" },
  { "time": "2019-07", "count": 200, "name": "c" },
]

dualAxes = Plot("DualAxes")

dualAxes.set_options({
  "appendPadding": 32,
  "data": [data1, data2],
  "xField": "time",
  "yField": ["value", "count"],
  "legend": {
    "position": "top",
  },
  "geometryOptions": [
    {
      "geometry": "line",
      "seriesField": "type",
      "lineStyle": {
        "lineWidth": 3,
    "value": 18000
}, {
    "city": "上海",
    "type": "米面",
    "value": 11000
}, {
    "city": "上海",
    "type": "特产零食",
    "value": 15000
}, {
    "city": "上海",
    "type": "茶叶",
    "value": 14000
}]

column = Plot('Column')

column.set_options({
    "appendPadding": 32,
    "data": data,
    "xField": "city",
    "yField": "value",
    "seriesField": "type",
    "isGroup": True,
    "columnStyle": {
        "radius": [20, 20, 0, 0],
    },
    "legend": {
        "position": "top"
    }
})
Exemple #23
0
def bullet(request):
    bul = Plot('Bullet')

    data = get(
        'https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/bullet.json'
    )

    bul.set_options({
        'data': data,
        'measureField': 'measures',
        'rangeField': 'ranges',
        'targetField': 'target',
        'xField': 'title',
        'color': {
            'range': ['#FFbcb8', '#FFe0b0', '#bfeec8'],
            'measure': '#5B8FF9',
            'target': '#39a3f4',
        },
        'label': {
            'measure': {
                'position': 'middle',
                'style': {
                    'fill': '#fff',
                },
            },
        },
        'xAxis': {
            'line': 'null',
        },
        'yAxis': False,
        'legend': {
            'custom':
            True,
            'position':
            'bottom',
            'items': [
                {
                    'value': '差',
                    'name': '差',
                    'marker': {
                        'symbol': 'square',
                        'style': {
                            'fill': '#FFbcb8',
                            'r': 5
                        }
                    },
                },
                {
                    'value': '良',
                    'name': '良',
                    'marker': {
                        'symbol': 'square',
                        'style': {
                            'fill': '#FFe0b0',
                            'r': 5
                        }
                    },
                },
                {
                    'value': '优',
                    'name': '优',
                    'marker': {
                        'symbol': 'square',
                        'style': {
                            'fill': '#bfeec8',
                            'r': 5
                        }
                    },
                },
                {
                    'value': '实际值',
                    'name': '实际值',
                    'marker': {
                        'symbol': 'square',
                        'style': {
                            'fill': '#5B8FF9',
                            'r': 5
                        }
                    },
                },
                {
                    'value': '目标值',
                    'name': '目标值',
                    'marker': {
                        'symbol': 'line',
                        'style': {
                            'stroke': '#39a3f4',
                            'r': 5
                        }
                    },
                },
            ],
        },
    })

    bul.render('bullet.html')
    return HttpResponse(bul.render_html())
Exemple #24
0
    "value": 5382.9
}, {
    "country": "亚太地区",
    "date": 2015,
    "value": 5472.4
}, {
    "country": "亚太地区",
    "date": 2016,
    "value": 5585.5
}, {
    "country": "亚太地区",
    "date": 2017,
    "value": 5743.6
}]

area = Plot("Area")

area.set_options({
    "appendPadding": 32,
    "data": data,
    "xField": "date",
    "yField": "value",
    "seriesField": 'country',
    "smooth": True,
    "label": {},
    "legend": {
        "position": "top"
    }
})

area.render("Study/面积图/area.html")
Exemple #25
0
def scatter(request):
    sca = Plot('Scatter')

    # data = get('https://gitee.com/hjhcos/hjhcos.gitlab.io/raw/master/json/visual/scatter.json')
    data = get(
        'https://gw.alipayobjects.com/os/bmw-prod/0b37279d-1674-42b4-b285-29683747ad9a.json'
    )

    sca.set_options({
        'data':
        data,
        'appendPadding':
        30,
        # 'xField': 'x',
        # 'yField': 'y',
        'xField':
        'change in female rate',
        'yField':
        'change in male rate',
        'sizeField':
        'pop',
        'colorField':
        'continent',
        'color': ['#ffd500', '#82cab2', '#193442', '#d18768', '#7e827a'],
        # 'size': 5,
        'size': [4, 30],
        'shape':
        'circle',
        'pointStyle': {
            'fillOpacity': 0.8,
            'stroke': '#bbb',
            # 'stroke': '#777777',
            # 'lineWidth': 1,
            # 'fill': '#5B8FF9',
        },
        # 'regressionLine': {
        #     'type': 'quad',  # linear, exp, loess, log, poly, pow, quad
        # },
        'xAxis': {
            'min': -25,
            'max': 5,
            'grid': {
                'line': {
                    'style': {
                        'stroke': '#eee',
                    },
                },
            },
            'line': {
                'style': {
                    'stroke': '#aaa',
                },
            },
        },
        'yAxis': {
            'line': {
                'style': {
                    'stroke': '#aaa',
                },
            },
        },
        'quadrant': {
            'xBaseline':
            0,
            'yBaseline':
            0,
            'labels': [
                {
                    'content': 'Male decrease,\nfemale increase',
                },
                {
                    'content': 'Female decrease,\nmale increase',
                },
                {
                    'content': 'Female & male decrease',
                },
                {
                    'content': 'Female &\n male increase',
                },
            ],
        },
    })

    sca.render('scatter.html')
    return HttpResponse(sca.render_html())
Exemple #26
0
    },
    {
        "year": '2018',
        "value": 238
    },
    {
        "year": '2019',
        "value": 290
    },
    {
        "year": '2020',
        "value": 341
    },
]

line_registration = Plot("Line")

line_registration.set_options({
    "data": data_registration,
    "xField": "year",
    "yField": "value",
    "smooth": True,
    "label": {},
    # "point": {
    #     "size": 5,
    #     "shape": 'diamond',
    #     "style": {
    #         "fill": "white",
    #         "stroke": "#5B8FF9",
    #         "lineWidth": 2,
    #     }
Exemple #27
0
print(Familie_dict)

# 生成曲线图
data_Households = []
data_Populations = []
data_Families = []
for i in range(len(Dynastys)):
    data_Households.append({"朝代": Dynastys[i], "总户数": Households[i]})
for i in range(len(Dynastys)):
    data_Populations.append({"朝代": Dynastys[i], "总人数": Populations[i]})
for i in range(len(Dynastys)):
    data_Families.append({"朝代": Dynastys[i], "人每户": Families[i]})
print(data_Households)
print(data_Populations)
print(data_Families)
line_Households = Plot("Line")
line_Populations = Plot("Line")
line_Families = Plot("Line")
# 总户数
line_Households.set_options({
    "appendPadding": 32,
    "data": data_Households,
    "xField": "朝代",
    "yField": "总户数",
    "label": {},
    "smooth": True,
    "lineStyle": {
        "lineWidth": 3,
    },
    "point": {
        "size": 5,