# Bar(chart) with % of different values in Canvas. How?

**URL:** https://discuss.elastic.co/t/bar-chart-with-of-different-values-in-canvas-how/146936
**Category:** Kibana
**Created:** [September 1, 2018, 10:37am UTC](https://discuss.elastic.co/t/bar-chart-with-of-different-values-in-canvas-how/146936 "2018-09-01T10:37:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![GGorast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ggorast/32/34669_2.png) [@GGorast](https://discuss.elastic.co/u/GGorast)
#### Post date: [September 1, 2018, 10:37am UTC](https://discuss.elastic.co/t/bar-chart-with-of-different-values-in-canvas-how/146936/1 "2018-09-01T10:37:52Z")

</div>

I need to make a pie-like bar(chart) that will show different % of 100% of the values that I choose and color it differently. See the image for explanation.

 ![pielike_barchart](https://us1.discourse-cdn.com/elastic/original/3X/4/b/4b1a80fe4856780e715e6efdbf43d69d91244aa0.jpeg)

Tnx

---

<div class="post-metadata">

### Author: ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)
#### Post date: [September 4, 2018, 6:11pm UTC](https://discuss.elastic.co/t/bar-chart-with-of-different-values-in-canvas-how/146936/2 "2018-09-04T18:11:15Z")

</div>

We currently don't have any elements that can achieve this out the box. You can build your own custom function to render the chart you described. It would be similar to our `pie` element, but you'll want to create a render function that displays it as a bar instead of a pie chart. You can refer to our guides on making custom functions if you want to go down that route: [http://canvas.elastic.co/stories/index.html](http://canvas.elastic.co/stories/index.html).

It took a bit of hacking around with the plot element, but I created something similar using `demodata` as my datasource.

 ![14%20AM](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4c211a5b678e86f193f61df3e229e73cca538ed6.png)

Essentially, you have to make a stacked horizontal bar chart with the labels turned off and a bunch of markdown elements for the labels. It'll take a lot of manual positioning, and it's not very dynamic this way, but it gets the job done. Below are the expressions I used for each element.

### Bar Chart

 ![24%20AM](https://us1.discourse-cdn.com/elastic/original/3X/8/2/821ff93856a93286a831bdb8e39df075225237bc.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| pointseries x="value" y=0 color="state"
| plot 
  defaultStyle={seriesStyle lines=0 bars="0.75" points=0 horizontalBars=true stack=true} legend=false xaxis=false yaxis=false 
  seriesStyle={seriesStyle bars="0.75" points=0 horizontalBars=true label="done" color="#f5cc5d"}
  seriesStyle={seriesStyle bars="0.75" points=0 horizontalBars=true label="running" color="#e74b8b"}
  seriesStyle={seriesStyle bars="0.75" points=0 horizontalBars=true label="start" color="#4fbf48"}
| render

```

### Series Labels

![26%20AM](https://us1.discourse-cdn.com/elastic/original/3X/1/1/11bb7f86810bd9f05747d90b004faa7dbe2c392f.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "state" row=0} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

![32%20AM](https://us1.discourse-cdn.com/elastic/original/3X/0/4/04c9986836fc9abcd0041225e3875abe8ba85fc9.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "state" row=1} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

![38%20AM](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d1722d86522e8259462215fc9e1a3b6d9eb9608f.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "state" row=2} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

### Percentage Labels

![31%20AM](https://us1.discourse-cdn.com/elastic/original/3X/1/4/145f376ba7a05081a3c4848b0547b0fb049f199a.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "value" row=0 | formatnumber "0.0%"} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

![34%20AM](https://us1.discourse-cdn.com/elastic/original/3X/d/3/d341e2907013e34b2fbc22a2b7c97fe1d0ecc98e.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "value" row=1 | formatnumber "0.0%"} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

![37%20AM](https://us1.discourse-cdn.com/elastic/original/3X/2/9/29e188025488b404b4292807b117e2a4513c286d.png)

```auto
filters
| demodata
| staticColumn "total_docs" value={rowCount}
| ply by="state" fn={math {string {rowCount} " / " {getCell "total_docs"}}}
| markdown {getCell "value" row=2 | formatnumber "0.0%"} 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=36 align="center" color="#000000" weight="normal" underline=false italic=false}

```

---

<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 2, 2018, 6:11pm UTC](https://discuss.elastic.co/t/bar-chart-with-of-different-values-in-canvas-how/146936/3 "2018-10-02T18:11:16Z")

</div>

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