问题描述
我有一个类似于这样的堆叠标准化条形图: https://vega.github.io/editor/#/examples/vega-lite/stacked_bar_normalize 我正在尝试将相关百分比(每个条形段)显示为类似于以下内容的条形文本:https://gist.github.com/pratapvardhan/00800a4981d43a84efdba0c4cf8ee2e1
我尝试添加一个转换字段来计算百分比,但经过数小时的尝试仍然无法使其正常工作。 我失去了帮助? 我最好的尝试:
{
"description":
"A bar chart showing the US population distribution of age groups and gender in 2000.","data": {
"url": "data/population.json"
},"transform": [
{"filter": "datum.year == 2000"},{"calculate": "datum.sex == 2 ? 'Female' : 'Male'","as": "gender"},{
"stack": "people","offset": "normalize","as": ["v1","v2"],"groupby": ["age"],"sort": [{"field": "gender","order": "descending"}]
}
],"encoding": {
"y": {
"field": "v1","type": "quantitative","title": "population"
},"y2": {"field": "v2"},"x": {
"field": "age","type": "ordinal"
},"color": {
"field": "gender","type": "nominal","scale": {
"range": ["#675193","#ca8861"]
}
}
},"layer":[
{ "mark": "bar"},{"mark": {"type": "text","dx": 0,"dy": 0},"encoding": {
"color":{"value":"black"},"text": { "field": "v1","format": ".1f"}}
}
]
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)