为什么某些时间值没有绘制在此图表上?
Why are certain time values not plotting on this graph?
创建一个仅在每个月的 11/12 之前绘制 vega 点的散点图?我很困惑,因为我觉得一切都应该正常工作,但显然情况并非如此。这是数据的原因吗?或者图表的选择?感觉好像应该有一个解决方案但是通过文档我找不到一个
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"config": {"background": "#e6edf0"},
"title": {
"text": "Chart 1: Daily Cryptocurrency Returns",
"subtitle": "Daily returns for six high marketcap cryptocurrencies source: Binance.com ",
"subtitleFontStyle": "italic",
"subtitleFontSize": 10,
"anchor": "start",
"color": "black"
},
"data": {
"url": "https://raw.githubusercontent.com/andrewsnowdon/andrewsnowdon.github.io/main/Data_mega_final.csv",
"format": {"type": "csv"}
},
"selection": {
"Stockname": {
"type": "single",
"fields": ["Stockname"],
"bind": {
"input": "select",
"options": [
null,
"DAX",
"DOWJONES",
"FTSE100",
"NASDAQ",
"S&P500"
],
"name": "Pick an index: "
}
}
},
"transform": [
{"filter": {"selection": "Stockname"}},
{
"filter": {
"field": "Stockname",
"oneOf": [
"DAX",
"DOWJONES",
"FTSE100",
"NASDAQ",
"S&P500"
]
}
}
],
"height": 300,
"width": 1000,
"mark": {"type": "circle"},
"encoding": {
"x": {
"field": "Date",
"type": "temporal",
"title": "Date",
"axis": {"grid": false}
},
"y": {
"field": "Returns",
"type": "quantitative",
"title": "Daily Return (%)",
"scale": {"domain": [-20, 20]},
"axis": {"grid": false}
},
"color": {
"field": "Stockname",
"type": "nominal",
"scale": {"scheme": "inferno"},
"title": "Stockname",
"legend": {"orient": "top-left", "fillColor": "aliceblue"}
},
"tooltip": [
{"field": "Stockname", "title": "Stockname", "type": "ordinal"},
{"field": "Date", "title": "Date", "type": "temporal"},
{"field": "Returns", "title": "Return (%)", "type": "quantitative"}
]
}
}
您的源数据似乎使用 DD/MM/YYYY
格式存储日期,Javascript 日期解析假定为 MM/DD/YYYY
。因此,当天数大于 12 时,结果为无效日期。
您可以通过在规范中声明正确的日期格式来解决此问题:
"data": {
"url": "https://raw.githubusercontent.com/andrewsnowdon/andrewsnowdon.github.io/main/Data_mega_final.csv",
"format": {"type": "csv", "parse": {"Date": "date:'%d/%m/%Y'"}}
},
有关详细信息,请参阅 https://vega.github.io/vega-lite/docs/data.html#format。
创建一个仅在每个月的 11/12 之前绘制 vega 点的散点图?我很困惑,因为我觉得一切都应该正常工作,但显然情况并非如此。这是数据的原因吗?或者图表的选择?感觉好像应该有一个解决方案但是通过文档我找不到一个
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"config": {"background": "#e6edf0"},
"title": {
"text": "Chart 1: Daily Cryptocurrency Returns",
"subtitle": "Daily returns for six high marketcap cryptocurrencies source: Binance.com ",
"subtitleFontStyle": "italic",
"subtitleFontSize": 10,
"anchor": "start",
"color": "black"
},
"data": {
"url": "https://raw.githubusercontent.com/andrewsnowdon/andrewsnowdon.github.io/main/Data_mega_final.csv",
"format": {"type": "csv"}
},
"selection": {
"Stockname": {
"type": "single",
"fields": ["Stockname"],
"bind": {
"input": "select",
"options": [
null,
"DAX",
"DOWJONES",
"FTSE100",
"NASDAQ",
"S&P500"
],
"name": "Pick an index: "
}
}
},
"transform": [
{"filter": {"selection": "Stockname"}},
{
"filter": {
"field": "Stockname",
"oneOf": [
"DAX",
"DOWJONES",
"FTSE100",
"NASDAQ",
"S&P500"
]
}
}
],
"height": 300,
"width": 1000,
"mark": {"type": "circle"},
"encoding": {
"x": {
"field": "Date",
"type": "temporal",
"title": "Date",
"axis": {"grid": false}
},
"y": {
"field": "Returns",
"type": "quantitative",
"title": "Daily Return (%)",
"scale": {"domain": [-20, 20]},
"axis": {"grid": false}
},
"color": {
"field": "Stockname",
"type": "nominal",
"scale": {"scheme": "inferno"},
"title": "Stockname",
"legend": {"orient": "top-left", "fillColor": "aliceblue"}
},
"tooltip": [
{"field": "Stockname", "title": "Stockname", "type": "ordinal"},
{"field": "Date", "title": "Date", "type": "temporal"},
{"field": "Returns", "title": "Return (%)", "type": "quantitative"}
]
}
}
您的源数据似乎使用 DD/MM/YYYY
格式存储日期,Javascript 日期解析假定为 MM/DD/YYYY
。因此,当天数大于 12 时,结果为无效日期。
您可以通过在规范中声明正确的日期格式来解决此问题:
"data": {
"url": "https://raw.githubusercontent.com/andrewsnowdon/andrewsnowdon.github.io/main/Data_mega_final.csv",
"format": {"type": "csv", "parse": {"Date": "date:'%d/%m/%Y'"}}
},
有关详细信息,请参阅 https://vega.github.io/vega-lite/docs/data.html#format。