'Sorting in vegalite screws when changing values from fraction to percentage
I have specified sorting in vegalite api as -y as shown below:
vl.markLine().data(video_data).encode(
vl.x()
.fieldN('names') //nominal
.sort('-y'), // sort by -y
//...
vl.y()
.fieldQ('d') //quantitative
//...
When I dont have percentage values, it correctly sorts:
But when I have percentage values, it screws up sorting:
Why is this so?
Solution 1:[1]
The problem seems to be that the d values seem to be in string format.
Found answer as stated here.
Converting it to vegalite api:
vl.markLine()
.data(video_data)
.transform([{"calculate": "toNumber(datum.d)", "as": "d2"}]) //convert d to numeric d2
.encode(
vl.x()
.fieldN('names')
.sort('-y'),
//...
vl.y()
.fieldQ('d2') //notice d2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maha |


