Renaming label in canvas expression editor

Is there a way to rename label of graphics (pie chart, donut chart,...) with expression editor or in general canvas?
For instance there are codes like 0001, 0010, 0100 in the index documents which we would like to translate in the charts labels to e.g. 'error with connection', 'error with timing' and 'warning' as label content.

Hi @rndee,

thanks for reaching out. I looks like you could do that by a static lookup of values of one column in your data table. This should be possible by a combination of mapColumn and switch:

| demodata
| mapColumn name='country' expression={getCell "country" | switch {case "US" then="United States"} {case "UK" then="Great Britain"}}
| table
| render

The mapColumn overwrites the current values of the country column by looking up the current value of each row and executing the switch function. The switch maps certain values to other values, everything unknown will just be passed through.

Let me know if that helps!

Thank you for your fast response.
I've checked your solution, but get an error [mapColumn] > Can not cast 'render' to any of 'datatable' when insert you mapColumn line just before |render.
When I put your line just before my | pie hole entry I get the error message [mapColumn] > [getCell] > Column not found: 'resultcode'

Further information I want to share:
I run a SQL request and get this codes back as grouped element.

You have to put it just before the pie function because mapColumn operates on the datatable, not the specific visualization. It looks like your column is not called resultcode, but something else. If you render the data table to table visualization (using | table | render instead of your current pie function), you can see how the columns are called in the datatable.

I had to put the mapColumn line just below the sql query. And now it runs as expected!
Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.