设置domainMax,通过确定筛选数据集的最大值。

huangapple go评论64阅读模式
英文:

setting domainMax by determining the max of filtered datasets

问题

我正在使用Deneb PowerBi可视化工具,显示了一个男性/女性的人口金字塔。

目前,我正在通过对整个(男性+女性)数字进行聚合来定义轴的最大领域,这种方法可行,但不够优化:

设置domainMax,通过确定筛选数据集的最大值。

我想通过确定男性或女性的最大值来设置最大领域,以便充分利用可用的显示空间。

{
  "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:

设置domainMax,通过确定筛选数据集的最大值。

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

这是你要的吗?

设置domainMax,通过确定筛选数据集的最大值。

{
  "$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?

设置domainMax,通过确定筛选数据集的最大值。

{
"$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}}
}

huangapple
  • 本文由 发表于 2023年7月13日 20:28:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679392.html
  • deneb
  • powerbi
  • powerbi-desktop
  • vega-lite
  • visualization
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定