Y-Axis not sorting Ascending or Descending on Vega-Lite

Hello There,

I'm trying to plot a graph using Vega-Lite, everything works fine, but I need the Y-axis to be reversed. The most recent date on top and the older dates on bottom. I've tried use the sort, but nothing seems to work.

Here is my script:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.4.0.json",
  "title": "TOP 15 Causa de Pedir Diário",
  "data": {
    "url": {
      "index": "processos",
      "%context%": true,
      "body": {
        "aggs": {
          "causa_mes": {
            "composite": {
              "sources": [
                {
                  "mes_fiscal": {
                    "date_histogram": {
                      "field": "data_distribuicao",
                      "interval": "day",
                      "time_zone":"UTC"
                    }
                  }
                },
                {
                  "causa": {
                    "terms": {"field": "acao.keyword"}
                  }
                }
              ]
            }
          }
        }
      }
    },
    "format": {
      "property": "aggregations.causa_mes.buckets"
    }
  },
  "transform": [
    {"calculate": "datum.key.causa", "as": "causa"},
    {"calculate": "datum.key.mes_fiscal", "as": "mes"},
    {"calculate": "datum.doc_count", "as": "processos"},
    {"calculate": "datum.doc_count / 2", "as": "center"}
  ],
  "encoding": {
    "y": {
      "field": "mes",
      "type": "ordinal",
      "timeUnit":"daymonthyear",
      "sort": "descending",
      "axis": {"title": "Data"}
    },
    "x": {
      "field": "processos",
      "type": "quantitative",
      "axis": {"title": "Quantidade"},
      "stack": "zero"
    },
    "color": {
      "field": "causa",
      "type": "nominal",
      "legend": {"title": "Tipo de AçÃo"},
      "scale": {
        "range": [
          "#26478D",
          "#632678",
          "#406EB3",
          "#BA2F7D",
          "#BB0048"
        ]
      }
    },
    "order": {"field": "causa", "type": "quantitative"}
  },
  "layer": [
    {"mark": {"type": "bar", "color": "#26478d"}},
    {
      "mark": {
        "type": "text",
        "baseline": "middle",
        "dx": -15
      },
      "encoding": {
        "x": {
          "field": "processos",
          "type": "quantitative",
          "stack": "zero"
        },
        "text": {"field": "processos", "type": "nominal"},
        "color": {"value": "white"}
      }
    }
  ]
}

And this is my actual plot:

It is usually very difficult to debug Vega questions without having your data. To make it easier, please follow these steps to include data with your graph when posting:

  • Reduce your data query to the smallest possible dataset, e.g. set the time range to 15 minutes. It will work as long as it is not empty and represents your data well enough.
  • Open Browser Debugger (for Chrome, right click and click Inspect )
  • Switch to the Console tab
  • Copy the right command, paste it in the console at the > symbol and hit enter (check the schema in your graph to see if you use Vega or Vega-Lite)
JSON.stringify(VEGA_DEBUG.vega_spec)  // <-- if you use Vega
JSON.stringify(VEGA_DEBUG.vegalite_spec)  // <-- if you use Vega-Lite
  • Copy the entire result string into your post, or if it is too big, attach it as a file.

The data itself I can't post because it's from a client and is confidencial.
But I can post the mapping from the index I'm using to build the plot.

{
  "mapping": {
    "properties": {
      "acao": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "adv_parte_contraria": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "adv_parte_contraria_oab": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "adv_resp": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "area": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "bpo_id": {
        "type": "float"
      },
      "causa_de_pedir": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "causa_de_pedir2": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "comarca": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "data_audiencia_pendente": {
        "type": "date"
      },
      "data_bpo": {
        "type": "date"
      },
      "data_de_registro": {
        "type": "date"
      },
      "data_distribuicao": {
        "type": "date"
      },
      "data_encerramento": {
        "type": "date"
      },
      "empresa": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "escritorio": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "esfera": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "estado": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "fase_processual": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "foro": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "grupo": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "id": {
        "type": "float"
      },
      "id_do_processo": {
        "type": "float"
      },
      "juiz": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "motivo_encerramento": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "numero": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "orgao": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "pagto_pedidos": {
        "type": "float"
      },
      "parte_contraria": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "possivel_atualizado": {
        "type": "float"
      },
      "provavel_atualizado": {
        "type": "float"
      },
      "provisao": {
        "type": "float"
      },
      "provisao_atualizado": {
        "type": "float"
      },
      "remoto_atualizado": {
        "type": "float"
      },
      "resultado_encerramento": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "status_do_processo": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "sub_area": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "tipo_contingencia": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "usuario_cadastro": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "valor_da_causa": {
        "type": "float"
      },
      "vara": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

Hey @BrunoSdeMenezes, it's rather difficult to debug the issue that you're seeing without having the data. Can you create some sort of fake data we can use when recreating your issue by redacting the sensitive information?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.