- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 Vega-Lite 图表:
Open the Chart in the Vega Editor
目前我设置的比例如下:
"scale": {"domainMin": "2021-06-01"}
但是,我真正想要的是 domainMin
自动计算为数据中 notification_date
字段中的最新日期之前 6 个月。我看过 aggregate和 expressions , 但还不是很清楚。
如何获取 notification_date
的最大值并从中减去 6 个月,然后在 "domainMin"
中使用它?
编辑:澄清一下,我不想过滤
数据。我希望用户能够缩小或平移以查看初始 6 个月窗口之外的数据。我用 "scale": {"domainMin": "2021-06-01"}
得到了我想要的,但这很快就过时了。
最佳答案
我已经尝试将 params
和 expr
赋给 domainMin,但我无法通过 datum 使用
。expr
中的数据字段
我尝试的第二种方法适合您,在此您需要使用joinaggregate/calculate/filter
转换。您将手动收集最大年份和最大月份,然后使用它来过滤您的数据。
以下是修改后的配置或引用editor网址:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": "container",
"height": "container",
"config": {
"group": {"fill": "#e5e5e5"},
"arc": {"fill": "#2b2c39"},
"area": {"fill": "#2b2c39"},
"line": {"stroke": "#2b2c39"},
"path": {"stroke": "#2b2c39"},
"rect": {"fill": "#2b2c39"},
"shape": {"stroke": "#2b2c39"},
"symbol": {"fill": "#2b2c39"},
"range": {
"category": [
"#2283a2",
"#003e6a",
"#a1ce5e",
"#FDBE13",
"#F2727E",
"#EA3F3F",
"#25A9E0",
"#F97A08",
"#41BFB8",
"#518DCA",
"#9460A8",
"#6F7D84",
"#D1DCA5"
]
}
},
"title": "South Western Sydney Cumulative and Daily COVID-19 Cases by LGA",
"data": {
"url": "https://davidwales.github.io/nsw-covid-19-data/confirmed_cases_table1_location.csv"
},
"transform": [
{
"filter": {
"and": [
{"field": "lhd_2010_name", "equal": "South Western Sydney"},
{"not": {"field": "lga_name19", "equal": "Penrith"}}
]
}
},
{"calculate": "utcyear(datum.notification_date)", "as": "yearNumber"},
{"calculate": "utcmonth(datum.notification_date)", "as": "monthNumber"},
{
"window": [
{"op": "count", "field": "notification_date", "as": "cumulative_count"}
],
"frame": [null, 0]
},
{
"joinaggregate": [
{"field": "monthNumber", "op": "max", "as": "max_month_count"},
{"field": "yearNumber", "op": "max", "as": "max_year"}
]
},
{"calculate": "abs(datum.max_month_count-6)", "as": "min_month_count"},
{
"filter": "datum.min_month_count < datum.monthNumber && datum.max_year === datum.yearNumber"
}
],
"layer": [
{
"selection": {
"date": {"type": "interval", "bind": "scales", "encodings": ["x"]}
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {
"timeUnit": "yearmonthdate",
"field": "notification_date",
"type": "temporal",
"title": "Date"
},
"color": {
"field": "lga_name19",
"type": "nominal",
"title": "LGA",
"legend": {"orient": "top", "columns": 4}
},
"y": {
"aggregate": "count",
"field": "lga_name19",
"type": "quantitative",
"title": "Cases",
"axis": {"title": "Daily Cases by SWS LGA"}
}
}
},
{
"mark": "line",
"encoding": {
"x": {
"timeUnit": "yearmonthdate",
"field": "notification_date",
"title": "Date",
"type": "temporal"
},
"y": {
"aggregate": "max",
"field": "cumulative_count",
"type": "quantitative",
"axis": {"title": "Cumulative Cases"}
}
}
}
],
"resolve": {"scale": {"y": "independent"}}
}
关于vega-lite - 将 domainMin 设置为数据中最大日期之前的 6 个月,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70429932/
我正在尝试在 vega 中绘制/链接两个图,更具体地说是一个节点链接图和几个散点图。根据拖动如何处理节点链接图中的信号,我确实走得很远,但还不够... 为了简单起见,我将在此处仅使用两个散点图提供一些
我有一个 Vega 规范,需要修改工具提示: Vega Chart Editor - Donut Chart 如何从此工具提示中删除“startAngle”和“endAngle”? 我也可以只添加一个
下面是可行的,但是好像不太对 (see live demo) : vg.parse.spec(spec, function(chart) { var view = chart({ el:
在 Vega 中,我有多个数据源,有时我想将它们一个接一个地合并在一起。例如,给定源 A、B 和 C,有两列 - date 和 value,我可能想创建一个包含 date< 列的组合数据源、value
我有一系列转换,它们不是 Vega-Lite 解析器的“ friend ”。有没有办法获得比以下更好/更详细的错误消息: 具体来说:消息Ignoring an invalid transform 确实
我的数据包含 3 列 - 日期、类别和值。该类别是我想扩展的一个短字符串代码,例如“r”=>“常规”,“n”=>“禁止”等,并显示正确的图例字符串。有没有办法让映射 {"r":"regular", "
我尝试实现类似于 https://vimeo.com/177767802 中所示的动画(2 点 30 分) 我的代码如下: { "data": { "values": [ {"
我的数据包含 3 列 - 日期、类别和值。该类别是我想扩展的一个短字符串代码,例如“r”=>“常规”,“n”=>“禁止”等,并显示正确的图例字符串。有没有办法让映射 {"r":"regular", "
我尝试实现类似于 https://vimeo.com/177767802 中所示的动画(2 点 30 分) 我的代码如下: { "data": { "values": [ {"
我有一个时间序列图(简单的折线图),我想在图中添加一条或多条引用线,以表示边界(类似于 SPC 图表,最小值、最大值和平均值)。 这在 Vega-Lite 中可能吗? 谢谢。 我的图表的链接: EGV
Vega/Vega Lite 图周围有一个微弱的灰色边框......是否可以通过配置参数删除它,或者我是否需要渲染为 SVG 并使用 CSS 来执行此操作? 最佳答案 您可以覆盖默认的单元格样式 "c
我正在尝试创建 binomial distribution PMF 的直方图使用 vega js 规范。 这通常是如何完成的? vega expressions不包括用于选择或阶乘的函数,也不包括 s
我正在尝试创建一个饼图,其中弧按大小(顺时针)排序,但不知道如何排序。 看来“theta”中的“sort”参数指向“color”的默认顺序,例如: { "$schema": "https://ve
就像这个: https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2/ 我尝试了刻面、颜色 channel 和构图, 但结果并不
我试图在折线图中显示一些数据。但是,我的“Harvest_Year”数据(以年为单位的日期,如 2017 年或 2018 年)显示为我认为是一个字符串 我从 .csv 文件导入数据,以下是我将字符串更
VegaLite 自动分配颜色。金价是蓝色,银价是橙色,感觉不对。 如何指定显式颜色 - #F1C40F黄金和 #95A5A6为了银? 我也想保留data.values如下面的示例代码 - 作为一组单
我正在 Vega-Lite(使用 Altair 生成)中绘制条形图。使用 Vega-View API,我编写了一些代码,用户可以在其中选择条形,这会更改这些条形的颜色(以及在应用程序的其他地方做一些其
我想注册一个自定义 Multi-Hue Sequential Color Scheme在织女星精简版。 我对文档的阅读是我只能创建 config.range对象来设置自定义色阶,但无法公开插值函数,从
最近几天我一直在尝试重命名我的 vega-lite 图表上的图例标签。 通常,这些标签与其各自的数据字段名称匹配。我有一个案例,我想给它们一个更具描述性的名称,但不重命名原始数据名称。 一个简化的例子
如何在 VegaLite 中使用数组数据? 我想将数据用作数组 dates = [1, 2, 3] prices1 = [1, 2, 1] prices2 = [1.5, 1, 2] 代替 Veg
我是一名优秀的程序员,十分优秀!