Reputation: 175
By default, the starting point of the Y-Axis is 0. Normally this is fine, but I'd like Y-axis to start from the lowest value. How would I go about resolving this?
Thank you kindly in advance
Line-Chart with Y-axis at zero
I've tried viewing the documentation, but I can't quite figure it out. Adjusting "scale"? I'm not too sure. This solution would need to be dynamic so the Y-axis starting point changes depending on the first value in the axis.
EDIT: Thanks to David Bacci for resolving the requestion. Hovering over the "scale" object, Vega-Lite Online Editor add some documented contxt:
Upvotes: 1
Views: 491
Reputation: 30174
Set zero to false. e.g.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Line chart with conditional axis ticks, labels, and grid.",
"data": {"url": "data/stocks.csv"},
"transform": [
{"filter": "datum.symbol==='GOOG'"},
{"filter": {"field": "date", "timeUnit": "year", "range": [2006, 2007]}}
],
"width": 400,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"tickCount": 8,
"labelAlign": "left",
"labelExpr": "[timeFormat(datum.value, '%b'), timeFormat(datum.value, '%m') == '01' ? timeFormat(datum.value, '%Y') : '']",
"labelOffset": 4,
"labelPadding": -24,
"tickSize": 30,
"gridDash": {
"condition": {
"test": {"field": "value", "timeUnit": "month", "equal": 1},
"value": []
},
"value": [2, 2]
},
"tickDash": {
"condition": {
"test": {"field": "value", "timeUnit": "month", "equal": 1},
"value": []
},
"value": [2, 2]
}
}
},
"y": {"field": "price", "type": "quantitative", "scale":{"zero":false},}
},
"config": {"axis": {"domainColor": "#ddd", "tickColor": "#ddd"}}
}
Upvotes: 1