# Wrong percent calculation in pie chart - still exists

**URL:** https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555
**Category:** Help
**Created:** [March 19, 2021, 5:57pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555 "2021-03-19T17:57:14Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Viandoriel](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/viandoriel/32/22628_2.png) [@Viandoriel](https://discourse.pi-hole.net/u/Viandoriel)
#### Post date: [March 19, 2021, 5:57pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/1 "2021-03-19T17:57:14Z")

</div>

#### Please follow the below template, it will help us to help you!

Hi,  
I'm referring to my first Thread, where the percent calculation did not work (link below).  
Meanwhile this was fixed, but today I found out that the issue still seems to exist. Even if it's not that extrem anymore... maybe this is typicall german behaviour 😉 , but the overall percentage does not match 100%. So I think there must be something wrong.

> [@Wrong percent calculation in pie chart](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart/44277):
>
> Hi, I'm totally new at this board and just installed the pi-hole a week ago. It is working proberly, but I saw some strange behaviour regarding the pie charts in the dashboard and the calculation of them. It does not make sense and is mathematically wrong. My english is not the best, but hopefully you understand what I want to say. So here is a conclusion with some screenshots for better understanding: In the top it shows a blocking percentage by 27,1%, but in the pie chart below its at 33,8…

## Expected Behaviour:

Pie Chart: Sum of all single elements should be 100%

## Actual Behaviour:

 ![pie_charts](https://discourse.pi-hole.net/uploads/default/original/3X/1/e/1e87d50f9433e126b59834e8ec20712bf5f8a9fb.jpeg)  
Left Chart: 90 + 6,2 + 2,6 + 1 = **99,8 %**  
Right Chart: 34 + 15,9 + 34,4 + 17,4 = **101,7 %**

I know, I know, I know... shame on my head. This must be very picky and neglectable _(what I want to say in german: mega pingelig und zu vernachlässigen)_ but from my perspective, It's wrong. So there must be an error. It's absolutely not dramatically, but does not show the reality.

Regards,  
V.

---

<div class="post-metadata">

### Author: ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)
#### Post date: [March 19, 2021, 6:02pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/2 "2021-03-19T18:02:43Z")

</div>

Please upload a debug log and post **just the token** that is generated after the log is uploaded by running the following command from the Pi-hole host terminal:

```auto
pihole -d

```

or do it through the Web interface:

_ **Tools \> Generate Debug Log** _

---

<div class="post-metadata">

### Author: ![Viandoriel](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/viandoriel/32/22628_2.png) [@Viandoriel](https://discourse.pi-hole.net/u/Viandoriel)
#### Post date: [March 19, 2021, 6:09pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/3 "2021-03-19T18:09:51Z")

</div>

sorry, I forgot 🙈

Token#: zsp6hg8164

---

<div class="post-metadata">

### Author: ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)
#### Post date: [March 19, 2021, 7:54pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/5 "2021-03-19T19:54:37Z")

</div>

Output of the following from the Pi terminal:

`echo ">stats >quit" | nc localhost 4711`

---

<div class="post-metadata">

### Author: ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)
#### Post date: [March 19, 2021, 8:27pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/7 "2021-03-19T20:27:31Z")

</div>

You need to look at the raw data, the chart already does some rounding.

 ![Bildschirmfoto zu 2021-03-19 21-25-23](https://discourse.pi-hole.net/uploads/default/original/3X/d/8/d8ef36b674298dfbeacf28308e2cb1e6355e9b9c.png)

You can access it via `http://pi.hole/admin/api.php?getQueryTypes`

e.g. my PTR is 0.85%

---

<div class="post-metadata">

### Author: ![Viandoriel](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/viandoriel/32/22628_2.png) [@Viandoriel](https://discourse.pi-hole.net/u/Viandoriel)
#### Post date: [March 20, 2021, 9:17am UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/8 "2021-03-20T09:17:46Z")

</div>

Below the output:

```auto
~# echo ">stats >quit" | nc localhost 4711
domains_being_blocked 3800857
dns_queries_today 26909
ads_blocked_today 10294
ads_percentage_today 38.254860
unique_domains 8697
queries_forwarded 11579
queries_cached 4269
clients_ever_seen 22
unique_clients 21
dns_queries_all_types 26909
reply_NODATA 549
reply_NXDOMAIN 932
reply_CNAME 5520
reply_IP 17433
privacy_level 0
status enabled

```

So is it working as designed?  
For me it just looks strange all the time if you see that there should be 50% for example, but the pie does not show a half pie chart.

---

<div class="post-metadata">

### Author: ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)
#### Post date: [March 21, 2021, 11:55am UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/9 "2021-03-21T11:55:54Z")

</div>

> [@Viandoriel](#):
>
> So is it working as designed?

Could you provide the output of

> [@yubiuser](#):
>
> `http://pi.hole/admin/api.php?getQueryTypes`

? Note that you need to be logged in to the dashboard to be able to access this resource.

> [@yubiuser](#):
>
> e.g. my PTR is 0.85%

The difference comes from

[https://github.com/pi-hole/AdminLTE/blob/989e1ba0ca9f31570ea92a3139211d83cdcbd344/scripts/pi-hole/js/index.js#L813](https://github.com/pi-hole/AdminLTE/blob/989e1ba0ca9f31570ea92a3139211d83cdcbd344/scripts/pi-hole/js/index.js#L813)

which cuts away all the digits after the first one without rounding. We could use round to one digit, however, hacks are needed to do this as Javascript doesn't support rounding to a specific digit itself. Something like

```javascript
(Math.round(num * 10) / 10).toFixed(1)

```

could be used. The extra `toFixed` would be needed to avoid rounding results like `50.0000000032`.

I'm not convinced it's worth the effort. I wouldn't want to show more than one digit. For instance, one out of 7 queries could result in `14.285714285714286%` which is obviously useless.

---

<div class="post-metadata">

### Author: ![Viandoriel](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/viandoriel/32/22628_2.png) [@Viandoriel](https://discourse.pi-hole.net/u/Viandoriel)
#### Post date: [March 21, 2021, 5:15pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/10 "2021-03-21T17:15:15Z")

</div>

sure, here we go:

output is:

```auto
{"querytypes":{"A (IPv4)":91.18,"AAAA (IPv6)":7.27,"ANY":0,"SRV":0.02,"SOA":0,"PTR":1.49,"TXT":0,"NAPTR":0.03,"MX":0,"DS":0,"RRSIG":0,"DNSKEY":0,"NS":0,"OTHER":0,"SVCB":0,"HTTPS":0}}

```

and here is a screenshot from the same moment:

 ![scr2](https://discourse.pi-hole.net/uploads/default/original/3X/4/7/470ed616d61591ac00c54508c9e6b71cb4d5f018.jpeg)

right chart: 48,8 + 19,3 + 34,8 + 1,0 = 103,9 %

.  
.

> I'm not convinced it's worth the effort. I wouldn't want to show more than one digit. For instance, one out of 7 queries could result in `14.285714285714286%` which is obviously useless.

I fully agree with you. But I had the thought that there is maybe something bigger what is "defective".  
That#s why I wanted to mention it.

---

<div class="post-metadata">

### Author: ![system](https://discourse.pi-hole.net/uploads/default/original/3X/7/c/7c8792f649eeb921c5d2b4c41564ffa873d9a2b8.png) [@system](https://discourse.pi-hole.net/u/system)
#### Post date: [April 11, 2021, 5:15pm UTC](https://discourse.pi-hole.net/t/wrong-percent-calculation-in-pie-chart-still-exists/45555/11 "2021-04-11T17:15:35Z")

</div>

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