Search code examples
jsonsortingchartslinevega-lite

Sort on JSON line chart produces line connecting points in original sort


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.

No Sort (using count)

Sort using Average

Chart example Link to the sorted chart editor


Solution

  • The sorting is correct according to your spec. The reason it is muddled is because you have a sum on one axis and average on the other. If you make both the same, the dots can connect properly. e.g.

    Both average.

    enter image description here