Home > Enterprise >  Sort on JSON line chart produces line connecting points in original sort
Sort on JSON line chart produces line connecting points in original sort

Time:07-19

I'm trying to sort my y-axis of a line chart based on a value, the items on the y-axis does indeed sort, but the lines become unusable because the connecting points are still connecting based on the initial sort (alphabetical), so it creates a jumble of line. Trying to figure out how can I get the sort, to properly connect my points and not jump around using the alphabetical sort? The first picture the sort is count, so effectively no sort, but the second picture, where the lines no longer connect in order, is using average. Thanks in advance.

enter image description here

CodePudding user response:

It isn't clear what you're trying to do. Are you looking for this kind of sort?

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "data/barley.json"},
  "mark": {
    "type": "line",
    "tooltip": true,
    "point": true,
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "aggregate": "sum",
      "field": "yield",
      "sort": {"op": "average", "field": "yield", "order": "descending"}
    },
    "y": {"field": "variety", "type": "nominal"},
    "color": {"field": "site"}
  }
}

CodePudding user response:

Here is an example of the chart when I have a different aggregation for the sort. The line that I highlighted, it the path the dots connect is still looking at sort based on how they originally were. So the variety axis is now sorted based on the proper aggregation, but the dots connect on the old way. I highlighted the path one of the dots take. For Waseca (yellow line), the Wisconsin No. 38 connects to a No. 475 it would seem, not the category next to it. Highlighted Chart

  • Related