Comments (5)
This might be a Vega issue. Here is a corrected Vega spec changing the type to scale type to linear and the legend formatType to time.
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Stock prices of 5 Tech Companies over Time.",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"url": "data/stocks.csv",
"format": {"type": "csv", "parse": {"date": "date"}, "delimiter": ","},
"transform": [
{
"field": "date",
"type": "timeunit",
"units": ["year"],
"as": ["year_date", "year_date_end"]
},
{
"type": "aggregate",
"groupby": ["year_date", "date"],
"ops": ["mean"],
"fields": ["price"],
"as": ["mean_price"]
},
{
"type": "filter",
"expr": "(isDate(datum[\"date\"]) || (isValid(datum[\"date\"]) && isFinite(+datum[\"date\"]))) && isValid(datum[\"mean_price\"]) && isFinite(+datum[\"mean_price\"])"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "symbol",
"style": ["point"],
"from": {"data": "source_0"},
"encode": {
"update": {
"fill": {"value": "transparent"},
"stroke": {"scale": "color", "field": "date"},
"ariaRoleDescription": {"value": "point"},
"description": {
"signal": "\"date (year): \" + (timeFormat(datum[\"year_date\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Mean of price: \" + (format(datum[\"mean_price\"], \"\")) + \"; date: \" + (timeFormat(datum[\"date\"], '%b %d, %Y'))"
},
"x": {"scale": "x", "field": "year_date"},
"y": {"scale": "y", "field": "mean_price"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": {"data": "source_0", "field": "year_date"},
"range": [0, {"signal": "width"}]
},
{
"name": "y",
"type": "linear",
"domain": {"data": "source_0", "field": "mean_price"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "color",
"type": "linear",
"domain": {"data": "source_0", "field": "date" },
"range": {"scheme": "plasma"}
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"tickMinStep": {
"signal": "datetime(2002, 0, 1, 0, 0, 0, 0) - datetime(2001, 0, 1, 0, 0, 0, 0)"
},
"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 (year)",
"format": {
"signal": "timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})"
},
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"tickMinStep": {
"signal": "datetime(2002, 0, 1, 0, 0, 0, 0) - datetime(2001, 0, 1, 0, 0, 0, 0)"
},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Mean of price",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
],
"legends": [
{
"stroke": "color",
"format": "%b %d, %Y", "formatType":"time",
"title": "date"
}
]
}
from vega-lite.
Thanks! But if Vega is able to do this, it seems like Vega-Lite could be modified/fixed to output this kind of thing, right?
OTOH, looking at the compiled Vega for my example, it seems like it's just getting the range wrong.
from vega-lite.
Yes, here is the VL. The reason I said I thought it was a Vega issue is the range is being computed incorrectly by Vega when the type is time.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Stock prices of 5 Tech Companies over Time.",
"data": {"url": "data/stocks.csv"},
"mark": {"type": "point"},
"encoding": {
"x": {"timeUnit": "year", "field": "date"},
"y": {"aggregate": "mean", "field": "price", "type": "quantitative"},
"color": {
"field": "date",
"type": "quantitative",
"scale": {"scheme": "plasma"}, "legend":{"formatType": "time"}
}
}
}
from vega-lite.
Ah I see, thanks for that. Should I file a bug in the Vega repo?
from vega-lite.
I would do as they might know why the range is being calculated incorrectly.
from vega-lite.
Related Issues (20)
- Conditional expression to `labelColor` in `header` is not translated to Vega correctly
- MarkDef docs contains composite marks in docstring
- Add possibility for vconcat => columns => expression
- Default projection changes when `repeat` is used with the geoshape mark HOT 1
- Domain is behind bars for horizontal bar chart. Incorrect z-index
- Gap between marks on discrete scales if the chart size is not an even multiple of the number of steps HOT 2
- Setting `binSpacing` to 0 still leaves a gap between marks HOT 2
- Make javascript: urls work as values of href HOT 6
- Layer superimposing does not work as expected when both layers have `fill` or `color` specified HOT 2
- Support `bandPosition` for area marks
- Adding domain to scale on bar charts cause phantom bar to show up HOT 2
- Overwriting heigth and width values in concat operators HOT 2
- Documentation for Typescript usage needs to highlight that the spec should be declared "as const".
- Not possible to independently resolve latitude / longitude in concatenated geoshape chart with same projection HOT 2
- Your documentation for bullet chart has wrong label alignment HOT 1
- Bug (?): Incorrect Compilation of Signal Names in Bin Parameters Resulting in Non-Unique Dataset Names
- Default invalid value handling lacks stability between mark types
- Line with invalid null broken
- Stacked area charts broken in >=5.14.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vega-lite.