How to visualize complex data on Linux
Simon Quain shows how to visualize Covid-19 statistics and more with freely available open datasets and Timelion, a plugin for Elasticsearch.
When you purchase through links on our site, we may earn an affiliate commission.Here’s how it works.
Refining labels
While our graphs have been things of beauty, the labels in the top left of our charts aren’t as neat as they could be.
For instance, in the previous example we getq:countriesAndTerritories: United_Kingdom > sum(cases)as a label.
We can fix this, but we’re going to need regular expressions.
At its simplest, we can append.label(“LABEL_TEXT”)to the expression in question to label that part of it.
For example, to create a label “UK Cases” to a graph we’ve created earlier, it’s not much more of a jump to write.es(index=covid, q=“countriesAndTerritories: United_Kingdom”, metric=sum:cases).label(“UK Cases”).
We’re merely adding the.label()function to it.
Things get complicated if we want to create a label dynamically based on what the type of data we’re displaying.
Are you a pro? Subscribe to our newsletter
Sign up to the TechRadar Pro newsletter to get all the top news, opinion, features and guidance your business needs to succeed!
To show the number of cases per continent, we can split out the data by thecontinentExpfield and write.es(index=covid, split=continentExp:5, metric=sum:cases)
For Europe for example, this leaves us withq:* > continentExp:Europe > sum(cases)in the top left of our chart.
We want to capture the continent from this and set it to be the label for the Europe line.
To do this we can write.es(index=covid, split=continentExp:5, metric=sum:cases).label("$1”, “^.* > continentExp:(\S+) > .*").
This extracts everything that’s not a space character betweencontinentExp:and>and dynamically sets it as the label for that section of the graph.
With a regular expression we can capture a match into the$1variable by surrounding it with parentheses.^means the start of the line,\Scorresponds to everything that’s not a space character, the + matches between one and unlimited times and.*is a wildcard greedy match for anything.
While we’re on the subject of labelling, if you wanted to give your graph a title, you can easily do this by adding .title(GRAPH_TITLE) to the end of your expression as well.
Current page:Refining labels
iStorage Group acquires Kanguru Solutions as it looks to expand security offering
Phishing attacks surge in 2024 as cybercriminals adopt AI tools and multi-channel tactics
Arcane season 2 finally gave us the huge Caitlyn and Vi moment we’ve been waiting for – and its creators say ‘we couldn’t have done it in season one’