Midas,
I wanted to thank you for all of your help. The pie chart is displaying now, though I'm trying to put some finishing touches on it. At first I liked the interactive "adjust the pie chart" stuff, but in the end I think it's kind of pointless so I fiddled around and took out the "binding" part of the code and that seems to remove it remove it from the display. I also didn't want the angles to display when I hover over the pie chart so I removed the "datum" reference and put "datum.value" so it shows the number. I want to have it show the key and the value, but I can't figure out how to add two references. I looked it up and it seems like it should be an array:
"tooltip": [{"signal": "datum.value"}{"signal":"datum.key"}]
but that doesn't seem to work as I either get an error or the last value that I put (i.e. datum.key) is the only one that is shown.
I figured out how to add a legend, though that was harder than I had anticipated. One thing I cannot for the life of me figure out is how to change the size of the title. I have looked at "titlefontSize" and "fontSize" but nothing seems to work. Not sure if this is a bug or something that I am doing wrong.
Lastly - at least for now, the calculation seemed to be working until I looked a little closer. As of now I have 1103 records in my index. Of those 1103 records 324 of them don't even have the field in their record (if I'm using the wrong syntax feel free to correct me). Of those 1103, 559 have the field, but the field is empty, which means 220 of the records have the field and have it populated with someone's name. So here's the catch, the pie chart is only finding the records that don't have the POC field. So it's showing 324 as missing and all of the empty strings as well as the 220 complete as "present" (or complete). I've tried messing around the formula but nothing is working yet. Rather than looking for the empty string, I was thinking that perhaps I could say datum.key == MISSING or the key length is 0. But I'm not sure that is even a field...it doesn't error out when I put datum.key.length but it also doesn't change the calculation.
Any thoughts?
"type": "formula",
"as": ["key"],
"expr": "datum.key && (datum.key == 'MISSING' || datum.key.length == '0') ? 'Missing' : 'Complete'"
And for what it's worth, this is the entire code:
{
"$schema": "https://vega.github.io/schema/vega/v3.3.1.json",
// "width": 400,
// "height": 400,
"autosize": "fit"
// {"type": "fit", "contains": "content", "resize": true},
"title": {text: "Business PoC Completion", "fontSize": 24},
"config": {"kibana": {"hideWarnings": true}},
"signals": [
{
"name": "startAngle", "value": 0,
// the bind statements will create a slider to allow dynamic adjustments to the pie chart
// "bind": {"input": "range", "min": 0, "max": 6.29, "step": 0.01}
},
{
"name": "endAngle", "value": 6.29,
// "bind": {"input": "range", "min": 0, "max": 6.29, "step": 0.01}
},
{
"name": "padAngle", "value": 0,
// "bind": {"input": "range", "min": 0, "max": 0.1}
},
{
"name": "innerRadius", "value": 0,
// "bind": {"input": "range", "min": 0, "max": 90, "step": 1}
},
{
"name": "cornerRadius", "value": 0,
// "bind": {"input": "range", "min": 0, "max": 10, "step": 0.5}
},
{
"name": "sort", "value": false,
// "bind": {"input": "checkbox"}
},
{
"name": "strokeWidth",
"value": 2
}
],
"data": [
{
"name": "source",
"url": {
"%context%": true,
"index": "my_custom_index",
"body": {
"size": 0,
"aggs": {
"2": {
"terms": {
"field": "business_poc.keyword",
"order": {
"_count": "desc"
},
"missing": "MISSING",
"size": 5000
}
}
}
}},
"format": {"property": "aggregations.2.buckets"},
"transform": [
{
"type": "project",
"fields": ["key", "doc_count"],
"as": ["key", "value"]
// This renames the business_poc.keyword and count fields as key and value. Key = bars & value = size.
},
{
"type": "formula",
"as": ["key"],
"expr": "datum.key && (datum.key == 'MISSING' || !datum.key.length > '0') ? 'Missing' : 'Complete'"
// This formula overwrites the key with either Missing or Complete, so you can show this for a pie chart or basic bar chart.
},
{
"type": "aggregate",
"groupby": ["key"],
"fields": ["value"],
"ops": ["sum"],
"as": ["value"]
// This groups all of those business_poc results as either present or missing so that we should get 1 record with Present along with a value and Missing with a value
},
{
"type": "pie",
"field": "value",
"startAngle": {"signal": "startAngle"},
"endAngle": {"signal": "endAngle"},
"sort": {"signal": "sort"}
}
]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"domain": {"data": "source", "field": "key"},
"range": {"scheme": "tableau10"}
}
],
"marks": [
{
"type": "arc",
"from": {"data": "source"},
"zindex": 1,
"interactive": true,
"encode": {
"enter": {
"fill": {"scale": "color", "field": "key"},
"x": {"signal": "width / 2"},
"y": {"signal": "height / 2"},
"tooltip": {"signal": "datum.value"}
"cursor": {"value": "cursor"}
},
"update": {
"startAngle": {"field": "startAngle"},
"endAngle": {"field": "endAngle"},
"padAngle": {"signal": "padAngle"},
"innerRadius": {"signal": "innerRadius"},
"outerRadius": {"signal": "if(width >= height, height, width) / 2"},
"cornerRadius": {"signal": "cornerRadius"},
"stroke": {"signal": "scale('color', datum.key)"},
"strokeWidth": {"signal": "strokeWidth"},
"fillOpacity": {"value": 0.9}
},
"hover": {
"fillOpacity": {"value": 0.6}
}
}
}
]
"legends": [
{
"orient": "top",
"fill": "color",
"encode": {
"title": {
"update": {
"fontSize": {"value": 18}
}
},
"labels": {
"interactive": true,
"update": {
"fontSize": {"value": 18},
"fill": {"value": "black"}
},
"hover": {
"fill": {"value": "value"}
}
},
"symbols": {
"update": {
"stroke": {"value": "transparent"}
}
},
"legend": {
"update": {
"stroke": {"value": "#ccc"},
"strokeWidth": {"value": 0}
}
}
}
}
]
}