Last active
April 8, 2022 22:06
-
-
Save helgasoft/d8f8f24198874ed5a132cd9744972683 to your computer and use it in GitHub Desktop.
R | ECharts | areaStyle and itemStyle, click event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(lubridate) | |
# add event for clicking on blank area | |
jscode <- c('','',"chart.getZr().on('click', function(e) { | |
if (!e.target) alert('blank area: '+JSON.stringify(e.event)); });") | |
set.seed(421) | |
df1 <- tibble(date= as_date("2021-11-01") + months(0:11), | |
x= 12*10^6 + rnorm(12,0,2000000), | |
y= 12*10^6 + rnorm(12,0,1000000)) | |
library(echarty) | |
p <- df1 %>% ec.init(js= jscode) | |
p$x$opts$yAxis <- list(axisLabel= list(formatter=ec.clmn('%@M', -1, scale=0.000001))) | |
p$x$opts$series <- list( | |
list(type='line', name='lx', encode=list(y='x'), areaStyle=list(opacity=0.2,color="blue"), itemStyle=list(color='blue')), | |
list(type='line', name='ly', encode=list(y='y'), areaStyle=list(opacity=0.2,color="red"), itemStyle=list(color='red'))) | |
p$x$opts$legend <- list(show=TRUE) | |
p$x$on <- list( # event(s) with Javascript handler | |
list(event= 'legendselectchanged', | |
handler= htmlwidgets::JS("(evt) => alert('selected: '+evt.name);")) | |
) | |
p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for trusting our code. Glad to see you are taking it further.
For documentation purposes, please copy your question in Issues.
There is a solution and will be given there.