Kibana visualization - Customize legend labels - kibana

I have a stacked bar chart, split by a boolean field. This causes the legend to appear with two colours (cool!) but the legend has these values: true and false. To the reader, there is no context for what is true or false means.
In this case, the field name is is_active.
At the very least having the field name appear in the legend will help people read and understand the chart.
Better: Is there a way to replace "true" and "false" with "Active" and "Inactive" respectively?
I tried this Advanced->JSON Input:
{
"script": {
"inline": "doc['is_active'].value ? 'Active' : 'Inactive'",
"lang": "painless"
}
}
Which results in an error "String cannot be cast to java.lang.Number". If I replace the strings in the JSON Input with numbers, the numbers do indeed appear in the legend. No help though.

Instead of using term aggregation in split series bucket, use filter aggretation. Create two filters, one for true and one for false and apply custom labels there.

Related

In Observable Plot, how to sort/order the stack from a bin() transform?

I'm working on a stacked bar chart in Observable's new Plot library. It's not too bad coming from Vega and D3, but I cannot find or figure how to order the resulting stacked bars from the Plot.binX() I'm using.
My actual mark looks something like this today:
Plot.rectY(hourlyUsageData, Plot.binX({
y: "sum",
title: bin => bin[0].Name
}, {
x: d => d3.timeHour.count(d3.timeDay(d.DateTime), d.DateTime),
y: d => d.kWh,
thresholds: 24,
fill: "Name",
//order: "sum",
//reverse: true
}))
Plot.binX() does just fine, resulting in a chart in which the stack is ordered according to the input ordering.
I'd like the stack to be ordered based on a sum, and in fact if I add the Plot.stack option for order (see commented line above), I can order by sum:
Close! Now I just need to reverse the order. I hypothesize that, since I can use the order option, perhaps I can also use the reverse option (see commented line above). That doesn't seem to work.
My second hypothesis is that, since these transforms are supposed to be "composable", that I should be able to combine my binX with a stackY, but I cannot find an example of such a composition. I've tried Plot.stackY(Plot.binX({...}, { ... order:"sum", reverse:true }), and similar variations, but they don't seem to work either.
In summary, I'd love to know how to control the order of the stacks in my stacked bar chart while also using binX. Thanks!
Thank you. It seems that there is a bug and the {order} option is consumed for nothing by the bin transform. We'll try to fix this. In the meantime you can add it "outside" the bin transform like so:
Plot.rectY(data,
Plot.stackY({
...Plot.binX(
{ y: "count" },
{ x: "body_mass", fill: "species", order: "sum" }
),
reverse: true
})
).plot()
Pull-request to solve this issue: https://github.com/observablehq/plot/pull/439

Finding JSONPath value by a partial key

I have the following JSON:
{
"Dialog_1": {
"en": {
"label_1595938607000": "Label1",
"newLabel": "Label2"
}
}
}
I want to extract "Label1" by using JSONPath. The problem is that each time I get a JSON with a different number after "label_", and I'm looking for a consistent JSONPath expression that will return the value for any key that begins with "label_" (without knowing in advance the number after the underscore).
It is not possible with JSONPath. EL or Expression Language does not have sch capability.
Besides, I think you need to review your design. Why the variable name is going to be changed all the time? If it is changing then it is data and you need to keep it in a variable. You cannot keep data in data.

Kibana: Pie Chart slices based on beginning value of field only

I am trying to visualize field data but based on the first 3 characters within the string. Say the field contains "+44123456", I want the pie chart to visualize based on "+44" only.
Please assist me in achieving this with advanced JSON field ?
You can do it via using the "Advanced JSON" input field :
Try following script :
{
"script": "( _value.indexOf(' ') > 0 ? _value.substring(_value.lastIndexOf(' ')) : _value )"
}

visjs graph2d showMinorLines example

I want to hide the horizontal major/minor lines that appear on Graph2D Y-axis values of a scatter plot/timeline.
I have tried to make use of showMinorLines and showMajorLines without much success. The syntax am using is:
graph2d.setOptions({showMinorLines: false})
However, it generates an error that states:
Unknown option detected: "showMinorLines". Did you mean
"showMinorLabels"?
Problem value found at: options = { showMinorLines }
vis.js:23607 Errors have been found in the supplied options object.
Any help would be much appreciated?
Update: Attaching image.
Thanks for bringing this up. This is an fault in the documentation: in v4, this option has been renamed to get a more consistent API. You now have the following four related options:
{
showMinorLabels: true | false, // minor labels and lines on horizontal axis
showMajorLabels: true | false, // major labels and lines on horizontal axis
dataAxis: {
showMinorLabels: true | false, // minor labels and lines on vertical axis
showMajorLabels: true | false, // major labels and lines on vertical axis
}
}
We will fix the docs, sorry for the inconvenience.

Google charts tools Stacked chart

I'm new to Google Charts tools and I was wondering what I'am doing wrong. I want to make the BarChart (or ColumnChart) stacked by adding 'isStacked':true but then the chart gives me wrong data.
You can try it yourself on the Google playground with this code
(Just add 'isStacked':true to the options to see the wrong results)
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable({"cols":[{"id":"","label":"Date","type":"string"},
{"id":"","label":"Complaints","type":"number"},
{"id":"","label":"Compliments","type":"number"},
{"id":"","label":"Questions","type":"number"},
{"id":"","label":"Suggestions","type":"number"}],
"rows":[{"c":[{"v":"12\/2011"},{"v":30},{"v":0},{"v":0},{"v":0}]},
{"c":[{"v":"1\/2012"},{"v":93},{"v":"5"},{"v":0},{"v":0}]},
{"c":[{"v":"2\/2012"},{"v":82},{"v":"5"},{"v":0},{"v":0}]},
{"c":[{"v":"3\/2012"},{"v":72},{"v":"10"},{"v":0},{"v":0}]},
{"c":[{"v":"4\/2012"},{"v":68},{"v":"8"},{"v":0},{"v":0}]},
{"c":[{"v":"5\/2012"},{"v":59},{"v":"7"},{"v":0},{"v":0}]},
{"c":[{"v":"6\/2012"},{"v":30},{"v":"3"},{"v":"3"},{"v":0}]},
{"c":[{"v":"7\/2012"},{"v":37},{"v":"3"},{"v":"4"},{"v":"3"}]},
{"c":[{"v":"8\/2012"},{"v":31},{"v":"2"},{"v":"5"},{"v":0}]},
{"c":[{"v":"9\/2012"},{"v":47},{"v":"2"},{"v":"1"},{"v":"1"}]},
{"c":[{"v":"10\/2012"},{"v":67},{"v":0},{"v":"5"},{"v":"1"}]},
{"c":[{"v":"11\/2012"},{"v":38},{"v":"1"},{"v":"4"},{"v":0}]},
{"c":[{"v":"12\/2012"},{"v":14},{"v":"1"},{"v":"1"},{"v":"1"}]}
]});
// Create and draw the visualization.
new google.visualization.BarChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:1000, height:400,
vAxis: {title: "Year"},
hAxis: {title: "Cups"}}
);
}
I hope somebody can help me...
Thanks!
I just had the very same problem. The solution is, numeric values should NOT be between quotation marks, otherwise "3"+"4" becomes 34 instead of 7.
Just remove the " marks if there's a numeric value there.
cheers, greg
UPDATE: if you use 'f:' values as well, you will need the quotation marks again, otherwise mouseover might not work on the chart.
{"c":[{"v":"12\/2012"},{"v":14, "f":"14"},{"v":1, "f":"1"},{"v":1, "f":"1"},{"v":1, "f":"1"}]}

Resources