Created
August 18, 2020 05:28
-
-
Save bkamapantula/ab95645a3c224a58b1c54ce16b7a0082 to your computer and use it in GitHub Desktop.
Sort bars in vega-lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega-lite/v2.4.json", | |
"description": "Bar chart with text labels. Apply scale padding to make the frame cover the labels.", | |
"data": { | |
"values": [ | |
{"Metrics": "A1", "Percentage": 0.79}, | |
{"Metrics": "A2", "Percentage": 0.0399}, | |
{"Metrics": "A3", "Percentage": 0.9868}, | |
{"Metrics": "A4", "Percentage": 0.0536}, | |
{"Metrics": "A5", "Percentage": 0.9412}, | |
{"Metrics": "A6", "Percentage": 0.0536} | |
] | |
}, | |
"encoding": { | |
"y": { | |
"field": "Metrics", | |
"type": "nominal", | |
"sort": "-x" | |
}, | |
"x": { | |
"field": "Percentage", | |
"type": "quantitative", | |
"scale": {"padding": 10} | |
}, | |
"tooltip": [{ | |
"field": "Metrics", | |
"type": "nominal" | |
}, { | |
"field": "Percentage", | |
"type": "quantitative" | |
}] | |
}, | |
"layer": [ | |
{"mark": "bar"}, | |
{ | |
"mark": { | |
"type": "text", | |
"align": "left", | |
"baseline": "middle", | |
"dx": 3 | |
}, | |
"encoding": {"text": {"field": "Percentage", "type": "quantitative"}} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment