# Kibana metric plot with dynamic text based on the data

**URL:** <https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [September 2, 2022, 3:46pm UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565 "2022-09-02T15:46:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 2, 2022, 3:46pm UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/1 "2022-09-02T15:46:57Z")

</div>

In the kibana dashboard visualization I need an metric plot to show the dynamic text based on the data. With the previous month gain.  
 ![Social Media KPI](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cf3e09a50741f8edede6b1dda7e2035e709a9516.png)

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 26, 2022, 12:37pm UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/2 "2022-09-26T12:37:37Z")

</div>

If your Kibana is up to date, you can use the new Lens metric visualization (of 8.5):

 ![Screenshot 2022-09-26 at 14.35.00](https://us1.discourse-cdn.com/elastic/original/3X/1/4/14c7dcdcfc754e9e10026ed9b05df9890cfd1d75.jpeg)

1. Subscribers gained config (primary metric) (if a subscriber is a single entry document in elasticsearch):  

2. Ratio of percentage increase from the previous month:

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 27, 2022, 6:03am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/3 "2022-09-27T06:03:35Z")

</div>

Thanks for the solution @Marta_Bondyra , does Kibana 8.4 lens metric allow only primary and secondary metrics, is there any way that I could have more than 2 metrics. As of now I'm using TSVB metric to show three metrics where I have to transform the data and add new fields as previous\_month and the change in order to display it, but in this i can see that the query will automatically get the previous month data.

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 27, 2022, 6:43am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/4 "2022-09-27T06:43:46Z")

</div>

The new metric only allows two metrics, so the recommended approach is to use more than one visualisation to present more data.

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 27, 2022, 9:01am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/5 "2022-09-27T09:01:54Z")

</div>

Hey @eleven_e sorry for leading you into wrong direction, I confused the Kibana version - the reduced time range will be released in a couple of weeks from now in a version 8.5 so you'll have to wait a little to use it. Again, sorry!

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 29, 2022, 6:23am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/6 "2022-09-29T06:23:18Z")

</div>

Thanks @Marta_Bondyra

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 29, 2022, 6:24am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/7 "2022-09-29T06:24:00Z")

</div>

Hi @Marta_Bondyra is there anyway that i could use different colors for each bar in a bar graph?  
Thanks

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 29, 2022, 6:25am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/8 "2022-09-29T06:25:25Z")

</div>

Thanks for the help @Marta_Bondyra , but i need to show the current month value, the previous month value and the change in a single metric is there any way?

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 29, 2022, 6:57am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/9 "2022-09-29T06:57:01Z")

</div>

When it comes to the different colors for different bars, this is something that we don't plan to support in Lens/Visualize, but you could use Vega, which is more complicated to write. However, maybe there are some workarounds in Lens that could serve you. Color on the bar chart can be set by `breakdown` dimension. If you know the values of the field that are different for each graph, you can set up the exact filters to achieve it, below is the example configuration.

Tell me more about your usecase and I'll try to figure it out.

For a string field:

 ![Screenshot 2022-09-29 at 08.49.44](https://us1.discourse-cdn.com/elastic/original/3X/e/f/ef7d8b63cab78df39ca4df14d0f87e2dc82667ad.jpeg)

 ![Screenshot 2022-09-29 at 08.49.48](https://us1.discourse-cdn.com/elastic/original/3X/8/c/8c04afe13577fef4a283eb469c5ac38e772d6d9f.jpeg)  
For a timefield with an interval of 1d:

 ![Screenshot 2022-09-29 at 08.55.47](https://us1.discourse-cdn.com/elastic/original/3X/6/e/6ee5c978bf3f548c4948e352858a78ad60b667de.jpeg)  
 ![Screenshot 2022-09-29 at 08.55.43](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cbb61ca4b5831c95e642274149ef333166aa40ed.jpeg)  
 ![Screenshot 2022-09-29 at 08.55.39](https://us1.discourse-cdn.com/elastic/original/3X/7/7/77f49b7e77f3dd27dfd86b00e29e44d1cc5d47f8.jpeg)

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 29, 2022, 7:05am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/10 "2022-09-29T07:05:57Z")

</div>

Yes, this is easy and possible in existing versions!

1. Set your time picker on current month.
2. Create a visualization with a formula: `count() - count(shift='1M')`. Count() gives you this month results, count with a timeshift the previous month.

 ![Screenshot 2022-09-29 at 09.06.48](https://us1.discourse-cdn.com/elastic/original/3X/7/7/772b61eb0629c6c29b5194eab1d4b11171af6eeb.png)

 ![Screenshot 2022-09-29 at 09.04.35](https://us1.discourse-cdn.com/elastic/original/3X/0/4/0418d3fa998b9457d4078c866a5856f7a5b98184.jpeg)  
 ![Screenshot 2022-09-29 at 09.04.31](https://us1.discourse-cdn.com/elastic/original/3X/0/2/02839e07157c5aa7aa1105198a06b1e40d8a50f8.jpeg)

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 30, 2022, 3:26am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/11 "2022-09-30T03:26:33Z")

</div>

Thanks a lot @Marta_Bondyra , I'll try out this filter and breakdown.  
My use case is I have 2 columns, one is the product categories and the other is the total number purchased, I need a bar graph on each category and the total purchased sum. I'm able to get the plot but I get all the bar graph as same color, my expectation is that i need different color for each category i.e for each bar.  
Thanks @Marta_Bondyra

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [September 30, 2022, 3:27am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/12 "2022-09-30T03:27:46Z")

</div>

This is something great and useful.  
Thanks @Marta_Bondyra .

I have an another doubt regarding the backup and restore!

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [September 30, 2022, 7:04am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/14 "2022-09-30T07:04:01Z")

</div>

Try switching the chart type from `bar horizontal` to `bar horizontal stacked`:

 ![Screenshot 2022-09-30 at 09.02.00](https://us1.discourse-cdn.com/elastic/original/3X/c/5/c58d6d4bf319f3622eefef7d243cda9db75dad75.jpeg)

 ![Screenshot 2022-09-30 at 09.02.05](https://us1.discourse-cdn.com/elastic/original/3X/1/6/16ca9cefa46f476ce934a0069daa7039808c456a.jpeg)

---

<div class="post-metadata">

**Author:** ![eleven\_e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eleven_e/32/106651_2.png) [@eleven\_e](https://discuss.elastic.co/u/eleven_e)\
**Post date:** [October 3, 2022, 5:48am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/15 "2022-10-03T05:48:21Z")

</div>

Thanks @Marta_Bondyra .

---

<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 31, 2022, 5:49am UTC](https://discuss.elastic.co/t/kibana-metric-plot-with-dynamic-text-based-on-the-data/313565/16 "2022-10-31T05:49:04Z")

</div>

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