mattijn
5/17/2017 - 2:06 PM

vega3_datetime_linechart

{
  "$schema": "http://vega.github.io/schema/vega/v3.0.json",
  "autosize": "pad",
  "padding": 5,
  "signals": [
    {
      "name": "width",
      "update": "data('layout')[0].width"
    },
    {
      "name": "height",
      "update": "data('layout')[0].height"
    },
    {
      "name": "unit",
      "value": {},
      "on": [
        {
          "events": "mousemove",
          "update": "group()._id ? group() : unit"
        }
      ]
    }
  ],
  "data": [
    {
      "name": "source_0",
      "values":  [
{"date":1493078400000,"value":1.0},{"date":1493164800000,"value":0.7},{"date":1493251200000,"value":0.5},{"date":1493337600000,"value":1.2},{"date":1493424000000,"value":-999.0},{"date":1493510400000,"value":-999.0},{"date":1493596800000,"value":-999.0},{"date":1493683200000,"value":-999.0},{"date":1493769600000,"value":-999.0},{"date":1493856000000,"value":-999.0},{"date":1493942400000,"value":-999.0},{"date":1494028800000,"value":-999.0},{"date":1494115200000,"value":-999.0},{"date":1494201600000,"value":-999.0},{"date":1494288000000,"value":0.7},{"date":1494374400000,"value":-999.0},{"date":1494460800000,"value":-999.0},{"date":1494547200000,"value":-999.0},{"date":1494633600000,"value":-999.0},{"date":1494720000000,"value":-999.0},{"date":1494806400000,"value":-999.0},{"date":1494892800000,"value":-999.0}
			],
      "transform": [
        {"type": "formula", "as": "ff_dt", "expr": "datetime(datum.date)"},
        {
          "type": "collect",
          "sort": {
            "field": "date",
            "order": "descending"
          }
        }
      ]
    },
    {
      "name": "layout",
      "values": [
        {
          "_id": 269,
          "width": 200,
          "height": 200
        }
      ],
      "transform": [
        {
          "type": "formula",
          "as": "width",
          "expr": "200"
        },
        {
          "type": "formula",
          "as": "height",
          "expr": "200"
        }
      ]
    }
  ],
  "marks": [
    {
      "name": "main-group",
      "type": "group",
      "description": "Google's stock price over time.",
      "from": {
        "data": "layout"
      },
      "encode": {
        "update": {
          "width": {
            "field": "width"
          },
          "height": {
            "field": "height"
          },
          "fill": {
            "value": "transparent"
          }
        }
      },
      "marks": [
        {
          "name": "marks",
          "type": "line",
          "from": {
            "data": "source_0"
          },
          "encode": {
            "update": {
              "x": {
                "scale": "x",
                "field": "ff_dt"
              },
              "y": {
                "scale": "y",
                "field": "value"
              },
              "stroke": {
                "value": "#4c78a8"
              }
            }
          }
        }
      ],
      "scales": [
        {
          "name": "x",
          "type": "time",
          "domain": {
            "data": "source_0",
            "field": "ff_dt"
          },
          "nice":"year",          
          "range": "width"
        },
        {
          "name": "y",
          "type": "linear",
          "domain": {
            "data": "source_0",
            "field": "value"
          },
          "range": "height",
          "round": true,
          "nice": true,
          "zero": true
        }
      ],
      "axes": [
        {
          "scale": "x",
          "orient": "bottom",
          "tickCount": 5,
          "title": "date",
          "zindex": 1,
          "encode": {
            "labels": {
              "update": {
                "text": {
                  "signal": "timeFormat(datum.value, '%b %d, %Y')"
                },
                "angle": {
                  "value": -45
                },
                "align": {
                  "value": "right"
                },
                "baseline": {
                  "value": "middle"
                }
              }
            }
          }
        },
        {
          "scale": "x",
          "domain": false,
          "grid": true,
          "labels": false,
          "orient": "bottom",
          "tickCount": 5,
          "ticks": false,
          "zindex": 0,
          "gridScale": "y"
        },
        {
          "scale": "y",
          "format": "f",
          "orient": "left",
          "title": "price",
          "zindex": 1
        },
        {
          "scale": "y",
          "domain": false,
          "format": "s",
          "grid": true,
          "labels": false,
          "orient": "left",
          "ticks": false,
          "zindex": 0,
          "gridScale": "x"
        }
      ]
    }
  ]
}