pyecharts 第一个项目案例(汽车销售)
x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
(
Line(opts.InitOpts(theme=ThemeType.DARK))
.set_global_opts(
tooltip_opts=opts.TooltipOpts(is_show=False),
legend_opts=opts.LegendOpts(
textstyle_opts=opts.TextStyleOpts(
color='#90979C'
)
),
xaxis_opts=opts.AxisOpts(
axistick_opts=opts.AxisTickOpts(is_show=False)
),
yaxis_opts=opts.AxisOpts(
type_="value",
max_=900,
splitline_opts=opts.SplitLineOpts(
is_show=True
)
)
)
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="2020",
y_axis=y1_data,
symbol="circle",
symbol_size=10,
is_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
itemstyle_opts=opts.ItemStyleOpts(
color="#6f7de3"
)
)
.add_yaxis(
series_name="2021",
y_axis=y2_data,
symbol="circle",
symbol_size=10,
is_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
itemstyle_opts=opts.ItemStyleOpts(
color="#c257F6"
)
)
.render("pyecharts.html")
)
2)pyecharts中, markpoint的使用
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
(
Line(opts.InitOpts(bg_color="1A1835"))
.set_global_opts(
tooltip_opts=opts.TooltipOpts(is_show=False),
legend_opts=opts.LegendOpts(
textstyle_opts=opts.TextStyleOpts(
color='#90979C'
)
),
xaxis_opts=opts.AxisOpts(
type_="category",
axisline_opts=opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color="rgba(204,187,225,0.5)"
)
),
splitline_opts=opts.SplitLineOpts(
is_show=False
),
axistick_opts=opts.AxisTickOpts(
is_show=False
)
),
yaxis_opts=opts.AxisOpts(
type_="value",
max_=900,
splitline_opts=opts.SplitLineOpts(
is_show=False
),
axisline_opts=opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color="rgba(204,187,225,0.5)"
)
)
)
)
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="2020",
y_axis=y1_data,
symbol="circle",
symbol_size=10,
is_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
itemstyle_opts=opts.ItemStyleOpts(
color="#6f7de3"
),
markline_opts=opts.MarkPointOpts(
label_opts=opts.LabelOpts(
color="#FFF"
),
data=[opts.MarkPointItem(
type_="max",
name="最大值",
), opts.MarkPointItem(
type_="min",
name="最小值"
)]
)
)
.add_yaxis(
series_name="2021",
y_axis=y2_data,
symbol="circle",
symbol_size=10,
is_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
itemstyle_opts=opts.ItemStyleOpts(
color="#c257F6"
),
markline_opts=opts.MarkPointOpts(
label_opts=opts.LabelOpts(
color="#FFF"
),
data=[opts.MarkPointItem(
type_="max",
name="最大值",
), opts.MarkPointItem(
type_="min",
name="最小值"
)]
)
)
.render("pyecharts.html")
)
3)pyecharts中, 柱状图的使用案例
import pyecharts.options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
y3_data = [740, 230, 540, 310, 570, 520, 560]
bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
(
bar.set_global_opts(
legend_opts=opts.LegendOpts(
pos_top=12,
pos_right=10,
textstyle_opts=opts.TextStyleOpts(
color="#fff"
)
),
yaxis_opts=opts.AxisOpts(
type_="value",
max_=1000,
splitline_opts=opts.SplitLineOpts(
is_show=True,
linestyle_opts=opts.LineStyleOpts(
color="rgba(255,255,255,0.3)"
)
)
)
)
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="2019",
y_axis=y1_data,
)
.add_yaxis(
series_name="2020",
y_axis=y2_data,
)
.add_yaxis(
series_name="2021",
y_axis=y3_data,
)
).render("series_bar.html")