Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String functions as arguments are supported. #199

Merged
merged 4 commits into from Oct 4, 2020

Conversation

swsoyee
Copy link
Contributor

@swsoyee swsoyee commented Oct 4, 2020

Relate Issue #105 .

A function is added to search for a string in the argument and convert it.

Test

p <- mtcars %>%
  tibble::rownames_to_column("model") %>%
  e_charts(wt) %>%
  e_scatter(mpg, qsec, bind = model) %>%
  e_tooltip(
    formatter = htmlwidgets::JS(
      "function(params){
        return('<strong>' + params.name +
                '</strong><br />wt: ' + params.value[0] +
                '<br />mpg: ' + params.value[1])
                }
    "
    )
  )

p # plot

# extract the JSON
json <- p %>%
  e_inspect(json = TRUE,
            pretty = TRUE)

# print json
json

# rebuild plot
echarts_from_json(json) %>%
  e_theme("dark") # modify

I'm not sure if this would be good, as it affects all options of rendering.
Feel free to edit this PR.

@JohnCoene
Copy link
Owner

This is great, thank you! Can you please add yourself as contributor to the DESCRIPTION (if you want to)

Then I'll merge

@swsoyee
Copy link
Contributor Author

swsoyee commented Oct 4, 2020

Thank you John, I have add myself to the DESCRIPTION but not clear if I was done right.
Feel free to edit it! 😉

@JohnCoene JohnCoene merged commit d84df2a into JohnCoene:master Oct 4, 2020
JohnCoene added a commit that referenced this pull request Oct 4, 2020
swsoyee added a commit to swsoyee/echarts4r that referenced this pull request Oct 7, 2020
JohnCoene added a commit that referenced this pull request Oct 7, 2020
fixes #204 Fix quotation in LICENSE.md and Bug in the #199
@QinJun-1998
Copy link

QinJun-1998 commented Jan 21, 2021

Hello, I want to assign a name to each point of the graph drawn by e_scatter_3d. The effect is as follows:
image

In the official documentation of echarts, I saw that this requires assigning a name to each point in the data parameter. It does work when I modify the output html source code.
image
Since I can’t find a function or parameter to do it directly in R, I used the method mentioned above, first convert the chart to json and then modify the json by adding the names for all points, then convert it back to chart. In the case where I can successfully run the above example I got a blank page, the console prompts the following information:
image
The test code is as follows:

library(tidyverse)
library(echarts4r)
data.frame(
  x = 1:3, y = 1:3, z = 1:3
) %>% 
  e_charts(x) %>% 
  e_scatter_3d(y, z) %>% 
  e_tooltip() %>% 
  e_inspect(json = TRUE, pretty = TRUE) ->
  json
echarts_from_json(json)

Is there any way to solve this problem?

@swsoyee
Copy link
Contributor Author

swsoyee commented Jan 21, 2021

@QinJun-1998 Hi, you can make it by using this code

library(echarts4r)
data.frame(
  x = 1:3, y = 1:3, z = 1:3, name = c("a", "b", "c")
) %>% 
  e_charts(x) %>% 
  e_scatter_3d(y, z, name) %>% 
  e_labels(show = T) %>% # Optional, just for example
  e_tooltip()

image

The arrow in your sample is not the item name but the series name.
I'm using the e_labels just for show your an example which is actually not needed in your case.
If you want to put the item name at the top of the tooltip, you need to write a totally new cusomized formatter to make it.

@QinJun-1998
Copy link

@swsoyee Thank you very much, it does work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants