英文:
setting domainMax by determining the max of filtered datasets
问题
我正在使用Deneb PowerBi可视化工具,显示了一个男性/女性的人口金字塔。
目前,我正在通过对整个(男性+女性)数字进行聚合来定义轴的最大领域,这种方法可行,但不够优化:
我想通过确定男性或女性的最大值来设置最大领域,以便充分利用可用的显示空间。
{
"data": {"name": "dataset"},
"transform":
[
{
"calculate": "datum.Geschlecht == 'männlich' ? 'männlich' : 'weiblich'",
"as": "gender"
},
{
"joinaggregate": [{
"op": "sum",
"field": "KPI-Set Display",
"as": "MaxVal"
}]
}
],
"spacing": 0,
"hconcat":
[
{
"transform":
[
{
"filter":
{
"field": "gender",
"equal": "weiblich"
}
}
],
"title": "",
"mark":
{
"type": "bar",
"tooltip": true
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"x":
{
"aggregate": "sum",
"field": "KPI-Set Display",
"title": "weiblich & unbekannt",
"scale": {"domainMax":{"expr":"data('data_0')[0].MaxVal"}},
"axis":
{
"format": "s"
},
"sort": "descending"
}
}
},
{
"width": 20,
"view":
{
"stroke": null
},
"mark":
{
"type": "text",
"align": "center"
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"type": "ordinal",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"text":
{
"field": "Altersgruppe",
"type": "nominal"
}
}
},
{
"transform":
[
{
"filter":
{
"field": "gender",
"equal": "männlich"
}
}
],
"title": "",
"mark":
{
"type": "bar",
"tooltip": true
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"x":
{
"aggregate": "sum",
"field": "KPI-Set Display",
"title": "männlich",
"scale": {"domainMax":{"expr":"data('data_0')[0].MaxVal"}},
"axis":
{
"format": "s"
},
"sort": "ascending"
}
}
}
]
}
请注意,上述内容包含JSON格式的代码和配置信息,以更好地呈现所需的数据可视化。
英文:
I´m using the Deneb PowerBi visual, displaying a Population Pyramid for male / female
currently I´m defining the maxdomain of the axis by aggregating the whole (male+femal) numbers, which works, but isnt optimal:
I´d like to set the max domain by determining the max from male or female, so the available display space is optimal used
{
"data": {"name": "dataset"},
"transform":
[
{
"calculate": "datum.Geschlecht == 'männlich' ? 'männlich' : 'weiblich'",
"as": "gender"
},
{
"joinaggregate": [{
"op": "sum",
"field": "KPI-Set Display",
"as": "MaxVal"
}]
}
],
"spacing": 0,
"hconcat":
[
{
"transform":
[
{
"filter":
{
"field": "gender",
"equal": "weiblich"
}
}
],
"title": "",
"mark":
{
"type": "bar",
"tooltip": true
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"x":
{
"aggregate": "sum",
"field": "KPI-Set Display",
"title": "weiblich & unbekannt",
"scale": {"domainMax":{"expr":"data('data_0')[0].MaxVal"}},
"axis":
{
"format": "s"
},
"sort": "descending"
}
}
},
{
"width": 20,
"view":
{
"stroke": null
},
"mark":
{
"type": "text",
"align": "center"
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"type": "ordinal",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"text":
{
"field": "Altersgruppe",
"type": "nominal"
}
}
},
{
"transform":
[
{
"filter":
{
"field": "gender",
"equal": "männlich"
}
}
],
"title": "",
"mark":
{
"type": "bar",
"tooltip": true
},
"encoding":
{
"y":
{
"field": "Altersgruppe",
"axis": null,
"sort":
{
"field":"Sortierung",
"order":"descending"
}
},
"x":
{
"aggregate": "sum",
"field": "KPI-Set Display",
"title": "männlich",
"scale": {"domainMax":{"expr":"data('data_0')[0].MaxVal"}},
"axis":
{
"format": "s"
},
"sort": "ascending"
}
}
}
]
}
答案1
得分: 1
这是你要的吗?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A population pyramid for the US in 2000.",
"data": {"url": "data/population.json"},
"transform": [
{"filter": "datum.year == 2000"},
{"calculate": "datum.sex == 2 ? 'Female' : 'Male'", "as": "gender"},
{
"aggregate": [{"op": "sum", "field": "people", "as": "people"}],
"groupby": ["age", "gender"]
},
{"joinaggregate": [{"op": "max", "field": "people", "as": "MaxVal"}]}
],
"spacing": 0,
"hconcat": [
{
"transform": [{"filter": {"field": "gender", "equal": "Female"}}],
"title": "Female",
"mark": "bar",
"encoding": {
"y": {"field": "age", "axis": null, "sort": "descending"},
"x": {
"type": "quantitative",
"field": "people",
"title": "population",
"axis": {"format": "s"},
"scale": {"domainMax": {"expr": "data('source_0')[0].MaxVal"}},
"sort": "descending"
},
"color": {"field": "gender", "scale": {"range": ["#675193", "#ca8861"]}, "legend": null}
}
},
{
"width": 20,
"view": {"stroke": null},
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {"field": "age", "type": "ordinal", "axis": null, "sort": "descending"},
"text": {"field": "age", "type": "quantitative"}
}
},
{
"transform": [{"filter": {"field": "gender", "equal": "Male"}}],
"title": "Male",
"mark": "bar",
"encoding": {
"y": {"field": "age", "title": null, "axis": null, "sort": "descending"},
"x": {
"type": "quantitative",
"field": "people",
"title": "population",
"axis": {"format": "s"},
"scale": {"domainMax": {"expr": "data('source_0')[0].MaxVal"}}
},
"color": {"field": "gender", "legend": null}
}
}
],
"config": {"view": {"stroke": null}, "axis": {"grid": false}}
}
英文:
Is this what you're after?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A population pyramid for the US in 2000.",
"data": {"url": "data/population.json"},
"transform": [
{"filter": "datum.year == 2000"},
{"calculate": "datum.sex == 2 ? 'Female' : 'Male'", "as": "gender"},
{
"aggregate": [{"op": "sum", "field": "people", "as": "people"}],
"groupby": ["age", "gender"]
},
{"joinaggregate": [{"op": "max", "field": "people", "as": "MaxVal"}]}
],
"spacing": 0,
"hconcat": [
{
"transform": [{"filter": {"field": "gender", "equal": "Female"}}],
"title": "Female",
"mark": "bar",
"encoding": {
"y": {"field": "age", "axis": null, "sort": "descending"},
"x": {
"type": "quantitative",
"field": "people",
"title": "population",
"axis": {"format": "s"},
"scale": {"domainMax": {"expr": "data('source_0')[0].MaxVal"}},
"sort": "descending"
},
"color": {
"field": "gender",
"scale": {"range": ["#675193", "#ca8861"]},
"legend": null
}
}
},
{
"width": 20,
"view": {"stroke": null},
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {
"field": "age",
"type": "ordinal",
"axis": null,
"sort": "descending"
},
"text": {"field": "age", "type": "quantitative"}
}
},
{
"transform": [{"filter": {"field": "gender", "equal": "Male"}}],
"title": "Male",
"mark": "bar",
"encoding": {
"y": {
"field": "age",
"title": null,
"axis": null,
"sort": "descending"
},
"x": {
"type": "quantitative",
"field": "people",
"title": "population",
"axis": {"format": "s"},
"scale": {"domainMax": {"expr": "data('source_0')[0].MaxVal"}}
},
"color": {"field": "gender", "legend": null}
}
}
],
"config": {"view": {"stroke": null}, "axis": {"grid": false}}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论