Pie chart into Kibana dashboard

Hello all, i'm trying to do a pie chart in Kibana dashboard based on some data i have. I don't understand if i am missing something or is Kibana that just works differently.

Let's say i have the following data (n docs)

{
  date: '2020-12-01',
  pc: 23,
  smarphones: 50,
  tables: 3
},
{
  date: '2020-12-02',
  pc: 22,
  smarphones: 51,
  tables: 4
},
{
  date: '2020-12-03',
  pc: 21,
  smarphones: 48,
  tables: 5
}

...and so on...

I would like, given a time interval, to draw a pie chart based on sums of every field. So for example given period 2020-12-01 2020-12-03 i have pc=66, smartphones=149, tablets=12 so the pie chart would have 3 slices (pc=29%, smartphones=65%, tablets=6%)

I'm trying to do it but with no results. Is there something that i miss? thanks

Kibana's pie chart metric is based on a single field -- with your current document structure, it's going to be difficult to achieve what you are looking to do, because you want to look at the sum of 3 different fields.

However, if your documents were structured so that each category of thing you want to count is a separate document, you should be able to achieve what you're looking for more easily.

For example, if you had something like this...

{
  date: '2020-12-01',
  type: 'pcs',
  total: 23
},
{
  date: '2020-12-01',
  type: 'smartphones',
  total: 50
},
{
  date: '2020-12-01',
  type: 'tablets',
  total: 3
},
{
  date: '2020-12-02',
  type: 'pcs',
  total: 22
},
{
  date: '2020-12-02',
  type: 'smartphones',
  total: 51
},
...etc

Then in your pie chart you could do a sum aggregation on the total, and split the slices using a terms aggregation on the type, which I believe would achieve what you're looking for.

Thank you very much, i knew that something was wrong with my docs format. I re-populate my index with some data and then try again with your indications. I will also give you a feedback on what i'll achieve...thanks again

It is perfectly working. Thanks. Have a nice day!

1 Like

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