# Renaming label in canvas expression editor

**URL:** <https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [September 18, 2019, 5:34am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909 "2019-09-18T05:34:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rndee](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rndee](https://discuss.elastic.co/u/rndee)\
**Post date:** [September 18, 2019, 5:34am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/1 "2019-09-18T05:34:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [September 18, 2019, 8:04am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/2 "2019-09-18T08:04:44Z")

</div>

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`:

```auto
filters
| 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!

---

<div class="post-metadata">

**Author:** ![rndee](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rndee](https://discuss.elastic.co/u/rndee)\
**Post date:** [September 18, 2019, 9:59am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/3 "2019-09-18T09:59:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [September 18, 2019, 10:06am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/4 "2019-09-18T10:06:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rndee](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rndee](https://discuss.elastic.co/u/rndee)\
**Post date:** [September 18, 2019, 11:02am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/5 "2019-09-18T11:02:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 16, 2019, 11:02am UTC](https://discuss.elastic.co/t/renaming-label-in-canvas-expression-editor/199909/6 "2019-10-16T11:02:37Z")

</div>

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