...
Here, we have an example of a custom expression for Canvas:
...
In this example of a Metric element definition we can see that:
...
In Canvas, we’ll often use Elasticsearch SQL to retrieve the data for our visualizations. To prepare our queries and test out different variations, we can use Kibana DevTools. To do this, we just need to wrap the SQL query in a simple JSON object and then POST it to the _sql API endpoint. We’ll also need to add “?format=txt” as a query parameter to our POST request, to see the returned result nicely formatted in a text-based table.
...
While working with an element, we can click the Expression editor in the bottom-right corner. This gives us much more flexibility in changing how the element works. After we get comfortable with the expression language used in Canvas, you’ll notice it’s a more efficient way to work, rather than using the interface and clicking on buttons and menus to edit various functionality.
...
The documentation for Canvas functions and TinyMath functions will come in handy when you dive deeper into the expression editor.
...
Let’s create our first workpad in Canvas and learn how to build an infographic like the one in this example:
...
Adding a New Element
In the top-right corner, above our workpad, notice the Add element button. Let’s click on it and reveal a list of available elements with clear visual representations and descriptions.
Let’s add a new element and pick the Shape type from that list. We’ll use this to create a green background for the right side of our infographic.
...
Let’s open the Display section in the right pane and find the Fill box. We’ll use the following color code for the green:
Copy
Code Block |
---|
#0b974d |
...
Metrics
Now it’s time to add our metrics on the right side. To do this, we add a new element and select the Metric type from that list. After we drag it to its place, we also change the Metric and Label text color to white.
...
After we select the element we want to work with (in this case, the metric we just added), look in the right pane of Canvas for Selected element. Switch from the Display tab to the Data tab, (as we see in this image), and change the data source to Elasticsearch SQL. To change the data source, we click on the underlined, bold text, which might display “Demo data” initially, on some installations.
...
We’ll use the following SQL query, which will return the total number of documents in our index:
...
After hitting Save we’ll see a warning sign on the screen. The metric doesn’t yet have a source value to use to display data. To fix this, we need to switch back to the Display tab and select count_documents as our Value, (as seen in this image). “count_documents” is generated by our previous SQL query.
...
We should also enter the text “Logs”, to use as our Label.
...
On the right side, in the Selected element pane, we can see the three vertical dots menu option, in the top-right corner. By clicking on it, we can then Clone the element to quickly add similar ones. We can also do this by simply copying with CTRL+C and then pasting with CTRL+V. There’s also an option for saving elements, which we find in the My elements tab when adding a new element.
...
To add the rest of the metrics, clone the previous one three times and then add the following SQL queries under each one’s Data source.
...
The first one will be used as the logo. To add the logo, we add an Image element and then change the link to point to the Nginx logo.
...
Next, we’ll add an Image repeat element. As the name suggests, this repeats the defined image, for a number of times, based on underlying data. Similarly, Image reveal shows a portion (or percentage) of the image, based on underlying data.
We’ll use a simple globe icon from wikipedia to represent the 136 unique agents in the right green section of our workpad. After adding the element, you need to explicitly add the Image Size property. We then use the same SQL query in the data section as we used for our “Unique agents” metric.
...
We’ll also need to adjust the size of the repeated image so that they all fit in:
...
For nicer formatting, we can go to the Display section and hide the Pagination and column Header.
...
The second table will be very similar, but we’ll learn how to use functions as well.
...
It should be placed right after the ESSQL source definitions, after the SQL query line.
...
The function uses the NumeralJS library, which defines the formatting notations that can be applied.
...
Under the Default style, we’ll pick a green fill color to make it fit with the rest of the design.
...
Progress Charts
Let’s try taking this even further using Canvas expressions. We’ll apply it to a new element that we’ll add, a Progress Gauge chart.
...
The whole expression will look like this:
...
And this is the important part that calculates the number between 0 and 1 (the percentage), for the progress gauge element.
...
We should also choose the same green color fill for the element and also pick a bigger font size.
...
We finally created the entire infographic example we initially saw.
Congratulations, you’re ready to explore the incredible capabilities that Kibana Canvas has to offer – beautiful dynamic and interactive representations of your data in exactly the form your users need.
...
Cleaning Up
To make sure we can continue with the next lesson in a clean environment, let’s remove the changes we created in this lesson.
...
Finally, we remove the workpad we created in Kibana Canvas. To do this, we click in the bottom-left corner, on My Canvas Workpad.
...
Afterward, we check the box to the left of My Canvas Workpad. Finally, we click on the Delete button. And that gets back to where we first started.
...