How to group all the not topN together

I want to draw a pie-chart (or bar graph) containing (for example) the TOP 5 IPs/URLs and in a addition a single aggregated value called “other” showing the sum of all the other entries excluding the TOP 5.

for example, lets say i have the following values:
a = 10
b = 10
c = 10
d = 10
e = 10
f = 1
g = 1
h = 1
i = 1
j = 1

i want a pie-chart with
a = 10
b = 10
c = 10
d = 10
e = 10
others = 5

how can i accomplish this?