zl程序教程

您现在的位置是:首页 >  其它

当前栏目

pyecharts和pywebio随机画100条线翻页

100 随机 翻页 Pyecharts
2023-09-14 09:05:38 时间
from pyecharts import options as opts
from pyecharts.charts import Line3D
from pyecharts.faker import Faker
import numpy as np
from pywebio import *
from pywebio.output import *
from functools import partial

config(title="pyecharts_server", css_style=".container{margin-top: 0;max-width: 1000px;}")


def draw_data(a_data=np.random.randint(100, size=(100, 2, 3)).tolist()):
    c = Line3D(init_opts=opts.InitOpts(height="1000px"))

    for i, data in enumerate(a_data):
        c.add(
            str(i),
            data,
            xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_="value"),
            yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_="value"),
        )

    c.set_global_opts(
        visualmap_opts=opts.VisualMapOpts(
            max_=100, min_=0, range_color=Faker.visual_color
        ),
        title_opts=opts.TitleOpts(title=""),

    )
    return c.render_notebook()
def yanzhen_current(x):
    if x<=0:
        return 1
    elif  x>=99:
        return 99-1
    return x


def next_drawer():
    global current_data
    print(current_data)
    html = draw_data(total_data_data[current_data])
    with use_scope("show", clear=True):
        # put_text("ddddddddddddddddddddddd")

        put_html(html).style("color:red;height:880px;width:1000px;")
    with use_scope("v_show", clear=True):
        put_text("{}".format(current_data))

    current_data = yanzhen_current(current_data)
    current_data += 1

    # current_data -= 1


def up_drawer():
    global current_data
    print(current_data)
    html = draw_data(total_data_data[current_data])

    with use_scope("show", clear=True):
        # put_text("ddddddddddddddddddddddd")
        put_html(html).style("color:red;height:880px;width:1000px;")
    with use_scope("v_show", clear=True):
        put_text("{}".format(current_data))

    current_data =yanzhen_current(current_data)

    current_data -= 1


def main():
    put_column(
        [put_row([put_button("下一个", onclick=partial(next_drawer)),put_scope(name="v_show"), put_button("上一个", onclick=partial(up_drawer))],size="10%,80%,10%"),
         put_scope(name="show")],size="10%,90%")


if __name__ == '__main__':
    total_data_data = [np.random.randint(100, size=(100, 2, 3)).tolist() for _ in range(100)]
    current_data = 0
    # a=[i for i in range(100)]
    start_server(applications=main, port=8888)