Skip to content

Order of data with e_line #126

Description

@Ari04T

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions