Field value label alias/override
When building a chart it is currently to provide a label override. E.G. change the label from 'document.subdocument.field' to 'mylabel. There should also be an option to provide value aliases/label overrides; E.G. be able to alias an int field with value 0 to ''red". Imagine a document field "color" of type int, where int defines a color used by a client. In the charts these values 0/1/2/3 mean little as they do not describe the value; being able to provide an alias of 'red/blue/green/yellow' would make it more meaningful
This can be done with String Binning. The feature lets you put 1 or more strings into a category and assign a new name. If the original values are numbers, you will need to convert the type to a string for this to work.
-
Steve commented
Additionally, I want to override the label on the axis. For instance, the x-axis might be labeled "utc_endtime", but I want it to say "Month".
-
Sander commented
That's right, thank you for that suggestion. In my use case that actually works without any issues; I added an $addFields pipeline stage to my data sources to add an additional label field, which I then use in my charts.
-
AdminTom (Admin, MongoDB) commented
Thanks Sander, fair feature request. While we could definitely make this easier, you can accomplish this today with a calculated field using $cond or $switch, for example:
{
$switch: {
branches: [
{ case: { $eq: [ '$bedrooms', 1 ] }, then: "small" },
{ case: { $eq: [ '$bedrooms', 2 ] }, then: "medium" },
{ case: { $eq: [ '$bedrooms', 3 ] }, then: "large" }
],
default: "Something else"
}
}