echarts设置标题样式_Pyecharts全局配置项之标题配置项Pyecharts全局配置项共有23⼩项,今天通过Pyecharts创建树图、图表和实例,具体了解“TitleOpts:标题配置项”的使⽤⽅法。
1、tree来实现:
实现代码:
from pyecharts import options as opts
from pyecharts.charts import Tree
data = [
{
"name": "TitleOpts:标题配置项",
"children":[
{
"name": "标题",
"children":[
{"name": "名称",
'children':[{"name": "title= '标题名称',"},
{"name": "title= '标题可通过\\n换⾏'"},
],
},
{"name": "链接",
'children':[{"name": "title_link= 'www.baidu'"},
],},
{"name": "链接跳转⽅式",
'children':[{"name": "title_targe=blank',"},
{"name": "title_targe=self"},
],
},
],
},
{
"name": "副标题",
"children":[
{"name": "名称",
'children':[{"name": "title= '副标题名称',"},
{"name": "title= '副标题可通过\\n换⾏'"},
{"name": "链接",
'children':[{"name": "title_link= 'www.baidu'"},
],},
{"name": "链接跳转⽅式",
'children':[{"name": "title_targe='blank',"},
{"name": "title_targe='self'"},
],
},
],
},
{
"name": "位置",
"children":[
{"name": "左","children":[{"name": "pos_left=20"},],},
{"name": "右","children":[{"name": "pos_right=20"},],},
{"name": "上","children":[{"name": "pos_top=20"},],},
{"name": "下","children":[{"name": "pos_bottom=20"},],},
],
},
{
"name": "间距",
"children":[
textstyle{"name": "内边距","children":[{"name": "padding= 5"},{"name": "padding= [50,50,50,50],"}],},
{"name": "主副间距","children":[{"name": "item_gap=10"},],},
],
},
{
"name": "字体样式",
"children":[
{"name": "标题字体样式","children":[{"name": "title_textstyle_opts= opts.TextStyleOpts(color=\"red\"),"},],}, {"name": "副标题字体样式","children":[{"name": "subtitle_textstyle_opts= opts.TextStyleOpts(color=\"blue\"),"},],}, ],
}
]
c = (
Tree(init_opts=opts.InitOpts(width="1400px", height="800px", ))
.add("", data,is_roam= False,is_expand_and_collapse= False)
.set_global_opts(title_opts=opts.TitleOpts(title="TitleOpts:标题配置
项",subtitle='.set_global_opts(title_opts=opts.TitleOpts())'))
)
2、表格实现:
实现代码:
from pyechartsponents import Table
from pyecharts.options import ComponentTitleOpts
table = Table()
headers = ["属性", "代码", "说明",'举例']
rows = [
["TitleOpts()", 'title= None,','主标题⽂本,⽀持使⽤换⾏','title=\"标题配置项\"'],
["", 'title_link= None,', '主标题跳转 URL 链接','title_link=\'www.baidu\', '],
["", 'title_targe= None,','主标题跳转链接⽅式,默认值blank可选self和blank','title_target=None'],
["", 'subtitle= None,', '副标题⽂本,⽀持使⽤\\n 换⾏','subtitle=副标题'],
["", 'subtitle_link= None,', '副标题跳转 URL 链接','subtitle_link=\"www.baidu\"'],
["", 'subtitle_target= None,', '副标题跳转链接⽅式默认值是blank,可选self','subtitle_target=self'],
["", 'pos_left= None,', '标题离容器左侧的距离,使⽤数值,百分⽐或left, center, right','pos_left=\"20%\"'],
["", 'pos_right= None,', '标题离容器右侧的距离,使⽤数值,百分⽐或left, center, right','pos_right=\"20%\"'],
["", 'pos_top= None,', '标题离容器上侧的距离,使⽤数值,百分⽐或left, center, right','pos_top=\"20%\"'],
["", 'pos_bottom= None,', '标题离容器下侧的距离,使⽤数值,百分⽐或left, center, right','pos_bottom=\"20%\"'],
["", 'padding=5,', '标题内边距,单位px,默认各⽅向内边距为5,接受数组分别设定上右下左边距',' padding= 5 ,\npadding= [50,50,50,50],'],
["", 'item_gap=10,', '主副标题之间的间距',' item_gap=10'],
["", 'title_textstyle_opts= None,', '主标题字体样式配置项,参考 `series_options.TextStyleOpts`','title_textstyle_opts=
opts.TextStyleOpts(color="red"),'],
["", 'subtitle_textstyle_opts= None,', '副标题字体样式配置项,参考 `series_options.TextStyleOpts`','subtitle_textstyle_opts= opts.TextStyleOpts(color="blue"),'],
table.add(headers, rows)
table.set_global_opts(title_opts=ComponentTitleOpts(title="TitleOpts:标题配置项表格",subtitle='.set_global_opts(title_opts=opts.TitleOpts())'))
3、实例:
实现代码:
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(
title= '主标题',
title_link= None,
title_target= None,
subtitle= '副标题',
subtitle_link= None,
subtitle_target= None,
pos_left= None,
pos_right= None,
pos_top=5,
pos_bottom= None,
padding= [5,10,5,10],
item_gap= 30,
title_textstyle_opts= opts.TextStyleOpts(color="red"),
subtitle_textstyle_opts= opts.TextStyleOpts(color="blue"),
)
)
)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论