Search code examples
vega-lite

Show day and month from epoch timestamp with vega-lite


I have this vega-lite spec and I'd like to show the day and month in the x axis from an epoch timestamp:

{
  "data": {
    "values": [
      {"date": "1325376000000", "price": 0},
      {"date": "1325462400000", "price": 100},
      {"date": "1325548800000", "price": 30}
    ]
  },
  "mark": "line",
  "encoding": {
    "x": {"field": "date"},
    "y": {"field": "price", "type": "quantitative"}
  },
  "width": "container"
}

This is the current result:

vega-lite chart

I tried using transformations with no luck.


Solution

  • You mean like this?

    enter image description here

    {
      "data": {
        "values": [
          {"date": "1325376000000", "price": 0},
          {"date": "1325462400000", "price": 100},
          {"date": "1325548800000", "price": 30}
        ],
        "format": {"parse": {"date": "date:'%Q'"}}
      },
      "mark": "line",
      "encoding": {
        "x": {"field": "date", "timeUnit": "yearmonthdate", "type": "ordinal"},
        "y": {"field": "price", "type": "quantitative"}
      },
      "width": "container"
    }