{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Line chart with conditional axis ticks, labels, and grid.", "background": "white", "padding": 5, "width": 400, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/stocks.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [ {"type": "filter", "expr": "datum.symbol==='GOOG'"}, { "type": "filter", "expr": "inrange(time(datetime(year(datum[\"date\"]), 0, 1, 0, 0, 0, 0)), [time(datetime(2006, 0, 1, 0, 0, 0, 0)), time(datetime(2007, 0, 1, 0, 0, 0, 0))])" } ] } ], "marks": [ { "name": "marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"date\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "#4c78a8"}, "description": { "signal": "\"date: \" + (timeFormat(datum[\"date\"], '%b %d, %Y')) + \"; price: \" + (format(datum[\"price\"], \"\"))" }, "x": {"scale": "x", "field": "date"}, "y": {"scale": "y", "field": "price"}, "defined": { "signal": "isValid(datum[\"date\"]) && isFinite(+datum[\"date\"]) && isValid(datum[\"price\"]) && isFinite(+datum[\"price\"])" } } } } ], "scales": [ { "name": "x", "type": "time", "domain": {"data": "source_0", "field": "date"}, "range": [0, {"signal": "width"}] }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "field": "price"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "axes": [ { "scale": "x", "orient": "bottom", "tickCount": 8, "gridScale": "y", "grid": true, "encode": { "grid": { "update": { "strokeDash": [ { "test": "time(datetime(2012, month(datum[\"value\"]), date(datum[\"value\"]), 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))", "value": [] }, {"value": [2, 2]} ] } } }, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "date", "tickCount": 8, "labelFlush": true, "labelOverlap": true, "encode": { "ticks": { "update": { "strokeDash": [ { "test": "time(datetime(2012, month(datum[\"value\"]), date(datum[\"value\"]), 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))", "value": [] }, {"value": [2, 2]} ] } }, "labels": { "update": { "text": { "signal": "[timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m') == '01' ? timeFormat(datum.value, '%Y') : '']" } } } }, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "price", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "config": { "axis": {"domainColor": "#ddd", "tickColor": "#ddd"}, "axisX": { "labelAlign": "left", "labelExpr": "[timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m') == '01' ? timeFormat(datum.value, '%Y') : '']", "labelPadding": -24, "labelOffset": 4, "tickSize": 30, "gridDash": { "condition": { "test": { "field": "value", "timeUnit": "monthdate", "equal": {"month": 1, "date": 1} }, "value": [] }, "value": [2, 2] }, "tickDash": { "condition": { "test": { "field": "value", "timeUnit": "monthdate", "equal": {"month": 1, "date": 1} }, "value": [] }, "value": [2, 2] } } } }