Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created October 27, 2025 18:43
Show Gist options
  • Select an option

  • Save cbaragao/181785081d06374508eba9669426582a to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/181785081d06374508eba9669426582a to your computer and use it in GitHub Desktop.
// SPECS
{
"data": {
"name": "dataset"
},
"title":"Sales Variance by Product",
"transform": [
{
//"calculate": "datum['Total Sales'] *.80","as": "target"
"calculate": "17000000", "as": "target"
}
],
"encoding": {
"y": {
"field": "Product",
"type": "nominal",
"sort":"-x",
"axis":{
"title":null,
"domain": false,
"ticks": false
}
},
"x": {
"field": "Total Sales",
"type": "quantitative",
"axis":{
"grid": false,
"ticks": false,
"labels": false,
"domain": false,
"title":null
}
}
},
"layer": [{
"mark": "bar",
"encoding": {
"color":{
"condition":{
"test": "datum['Total Sales'] > datum['target']", "value":"#009DDC"
},
"value": "#D8D2e1"
}
}
},{
"mark":{
"type": "text",
"align":"left",
"baseline":"middle",
"dx":3
},"encoding": {
"text": {
"field":"Total Sales","type": "quantitative", "format":".2s"
}
}
},
{
"mark":"tick",
"encoding": {
"x":{
"field":"target",
"type": "quantitative"
},
"y":{
"field":"Product",
"type": "nominal"
},
"color":{"value": "red"}
}
}]
}
//CONFIG
{
"view": {
"stroke": "transparent"
},
"tick": {
"thickness":3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment