JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
595 stars 81 forks source link

a question about e_on #512

Closed cailuzhaixing closed 1 year ago

cailuzhaixing commented 1 year ago

I want to realize an example of the official, address: example

url<-'D:\\华为家庭存储\\编程\\R语言\\地图json\\neizang.svg'
svg_neizang<-url %>% readLines() %>% paste0(collapse = "")
df<-data.frame(name=c('heart','large-intestine','small-intestine','spleen','kidney','lung','liver'),value=c(121, 321, 141, 52, 198, 289, 139))
df %>% e_charts(name) %>% e_svg_register('svg',svg_neizang) %>% e_geo(map='svg',left=10,right='50%',selectedMode='multiple', blur=FALSE, emphasis=list(focus='self',itemStyle=list(color=NULL)
))  %>% e_grid(left='60%',top='20%',bottom='20%') %>% e_bar(value,x_index=1,y_index=1) %>% e_flip_coords() %>% e_on(list(seriesIndex=0),                                                                                                                                             
"function (event) {
      dispatchAction({
        type: 'highlight',
        geoIndex: 0,
        name: event.name
      });
    }",event='mouseover') %>% e_on(list(seriesIndex=0),
                     "function (event) {
      dispatchAction({
        type: 'downplay',
        geoIndex: 0,
        name: event.name
      });
    }",event='mouseout')

image But the actual mouse slip bar chart, the figure of human body structure can not be normal, can help have a look at what's the problem?

JohnCoene commented 1 year ago

Try this.

url<-'https://echarts.apache.org/examples/data/asset/geo/Veins_Medical_Diagram_clip_art.svg'

svg_neizang<-url %>% readLines() %>% paste0(collapse = "")

df <- data.frame(name=c('heart','large-intestine','small-intestine','spleen','kidney','lung','liver'),value=c(121, 321, 141, 52, 198, 289, 139))

e <- df %>% 
  e_charts(name, elementId = "MYCHART") %>% 
  e_svg_register('svg', svg_neizang) %>% 
  e_geo(map='svg',left=10,right='50%',selectedMode='multiple', blur=FALSE, emphasis=list(focus='self',itemStyle=list(color=NULL))) %>% 
  e_grid(left='60%',top='20%',bottom='20%') %>% 
  e_bar(value,x_index=1,y_index=1) %>% 
  e_flip_coords() %>% 
  e_on(
       list(seriesIndex=0),
  "function (event) {
  let c = get_e_charts('MYCHART');
        c.dispatchAction({
          type: 'highlight',
          geoIndex: 0,
          name: event.name
        });
      }",event='mouseover') %>% 
      e_on(list(seriesIndex=0),
      "function (event) {
  let c = get_e_charts('MYCHART');
        c.dispatchAction({
          type: 'downplay',
          geoIndex: 0,
          name: event.name
        });
      }",event='mouseout')