首先,加载recharts
:
library(recharts)
工具箱默认放置于1点钟位。
建议用chart %>% setToolbox(...)
格式调用setToolbox
.
所有函数名都有小驼峰法和小写连划线(Hadly Wickham推荐此法)两种形式。为了便于偷懒,还有缩写版(如toolbox缩写成tb)。
setToolbox(chart, show = TRUE, language = "cn", controls = c("mark",
"dataZoom", "dataView", "magicType", "restore", "saveAsImage"), pos = 1,
bgColor = "rgba(0,0,0,0)", borderColor = "#ccc", borderWidth = 0,
padding = 5, itemGap = 10, itemSize = 16, color = c("#1e90ff",
"#22bb22", "#4b0082", "#d2691e"), disableColor = "#ddd",
effectiveColor = "red", showTitle = TRUE, textStyle = NULL, ...)
set_toolbox(chart, show = TRUE, language = "cn", controls = c("mark",
"dataZoom", "dataView", "magicType", "restore", "saveAsImage"), pos = 1,
bgColor = "rgba(0,0,0,0)", borderColor = "#ccc", borderWidth = 0,
padding = 5, itemGap = 10, itemSize = 16, color = c("#1e90ff",
"#22bb22", "#4b0082", "#d2691e"), disableColor = "#ddd",
effectiveColor = "red", showTitle = TRUE, textStyle = NULL, ...)
setTB(chart, show = TRUE, language = "cn", controls = c("mark",
"dataZoom", "dataView", "magicType", "restore", "saveAsImage"), pos = 1,
bgColor = "rgba(0,0,0,0)", borderColor = "#ccc", borderWidth = 0,
padding = 5, itemGap = 10, itemSize = 16, color = c("#1e90ff",
"#22bb22", "#4b0082", "#d2691e"), disableColor = "#ddd",
effectiveColor = "red", showTitle = TRUE, textStyle = NULL, ...)
set_tb(chart, show = TRUE, language = "cn", controls = c("mark",
"dataZoom", "dataView", "magicType", "restore", "saveAsImage"), pos = 1,
bgColor = "rgba(0,0,0,0)", borderColor = "#ccc", borderWidth = 0,
padding = 5, itemGap = 10, itemSize = 16, color = c("#1e90ff",
"#22bb22", "#4b0082", "#d2691e"), disableColor = "#ddd",
effectiveColor = "red", showTitle = TRUE, textStyle = NULL, ...)
参数 | 要求 |
---|---|
chart |
|
show |
逻辑型,是否显示工具箱。默认为TRUE。如要把工具箱部件整体从Echarts对象中移除,设为NULL. |
language |
‘cn’或’en’,工具箱提示文本的语言 |
controls |
显示哪些工具箱控件,默认为’mark’, ‘dataZoom’, ‘dataView’, ‘magicType’, ‘restore’, ‘saveAsImage’. |
pos |
工具箱的时钟方位,默认为1,参见 |
bgColor |
工具箱背景色,默认为透明 (‘rgba(0,0,0,0)’). |
borderColor |
工具箱边框颜色,默认为’#ccc’. |
borderWidth |
工具箱边框宽度,默认为0px (不显示). |
padding |
工具箱内边距,默认为5px. 也可以是一个列表,分别定义上、右、下、左的内边距 |
itemGap |
工具项的间距,默认为10px. |
itemSize |
工具项的大小,默认为16px. |
color |
工具箱颜色列表,(循环应用). 默认为c(“#1e90ff”, “#22bb22”, “#4b0082”, “#d2691e”). |
disableColor |
失效工具项的颜色,默认为’#ddd’. |
effectiveColor |
触发的工具项的颜色,默认为’red’. |
showTitle |
逻辑型,是否显示工具标题,默认为TRUE. |
textStyle |
工具标签文本样式,默认为 |
… |
省略号 |
g <- echartr(iris, Sepal.Width, Petal.Width, Species)
g
初始显示工具箱,可关闭。
g %>% setToolbox(show=FALSE)
工具箱提示文本默认为中文。如果要显示为英文,language
设为’en’。
g %>% setToolbox(language='en')
移动工具箱。
g %>% setToolbox(pos=3)
只显示部分控件。
g %>% setToolbox(controls=c('mark', 'dataView'))
自定义样式。
g %>% setToolbox(textStyle=textStyle(
fontFamily='Times New Roman', color='purple', fontWeight='bold',
fontSize=16), bgColor='yellow', itemGap=20)
自定义控件颜色列表。
g %>% setToolbox(color=getColFromPal('hc'))