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

Order of data with e_line #126

Closed
Ari04T opened this issue Feb 12, 2020 · 3 comments
Closed

Order of data with e_line #126

Ari04T opened this issue Feb 12, 2020 · 3 comments

Comments

@Ari04T
Copy link

Ari04T commented Feb 12, 2020

Hello! Thank you for the wrapper for echarts, things are looking great.

I noticed that when I try to plot certain X and Y values, the chart reorders the data, so that lower X values are always plotted before higher X values.

For example, if I try to plot

data.frame(x = c(20, 50, 40),
           y = c(120, 200, 50)) %>% 
    e_charts(x) %>%
    e_line(y) 

I get the following
Rplot

However, when I see a plot with the same data at the echarts site https://www.echartsjs.com/examples/en/editor.html?c=line-in-cartesian-coordinate-system you can see that the chart is different.
image

Basically, the chart done natively with JS follows the order of the data, while the chart done with the R wrapper reorders the data. This is confirmed by inspecting the resulting code:

> data.frame(x = c(20, 50, 40),
+            y = c(120, 200, 50)) %>% 
+     e_charts(x) %>%
+     e_line(y) %>% 
+     e_inspect(
+         json = TRUE,
+         pretty = TRUE
+     )
{
  "yAxis": [
    {
      "show": true
    }
  ],
  "xAxis": [
    {
      "type": "value"
    }
  ],
  "legend": {
    "data": [
      "y"
    ]
  },
  "series": [
    {
      "data": [
        {
          "value": [20, 120]
        },
        {
          "value": [40, 50]
        },
        {
          "value": [50, 200]
        }
      ],
      "yAxisIndex": 0,
      "xAxisIndex": 0,
      "name": "y",
      "type": "line",
      "coordinateSystem": "cartesian2d"
    }
  ]
} 

Is there a way to override this type of behaviour? Thank you!

JohnCoene added a commit that referenced this issue Feb 12, 2020
JohnCoene added a commit that referenced this issue Feb 12, 2020
@JohnCoene
Copy link
Owner

I had not anticipated people needing to do this.

I have just added a reorder argument to the e_charts function to address this, reinstall the Github version.

# install.packages("remotes")
remotes::install_github("JohnCoene/echarts4r")
data.frame(
    x = c(20, 50, 40),
    y = c(120, 200, 50)
  ) %>% 
  e_charts(x, reorder = FALSE) %>%
  e_line(y)

Let me know if this works.

@Ari04T
Copy link
Author

Ari04T commented Feb 12, 2020

Perfect, it works as expected. That was a crazy quick response, thank you very much for your help.

@JohnCoene
Copy link
Owner

Thank you for submitting this please don't hesitate to share any other issue you run into.

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

No branches or pull requests

2 participants