Pie Chart metric slice size

Hi all,

I have trouble to create chart with "Metric - Slice size". I want to use the count aggregate with a specific property ( like unique count) but there's no options for it.

ex: I have list of records like below:

    [
            {"category": "A", "amount": 28 , { "customer_Id" : 1}},
            {"category": "A", "amount": 12, { "customer_Id" : 2}},
            {"category": "A", "amount": 18, { "customer_Id" : 2}},
            {"category": "B", "amount": 55, { "customer_Id" : 5}},
            {"category": "C", "amount": 43, { "customer_Id" : 3}},
            {"category": "D", "amount": 91, { "customer_Id" : 4}} ,
            {"category": "D", "amount": 31, { "customer_Id" : 5}}           
     ]

I want to create a pie chart which is splitted by category and count on the number of customer.

But I don't know how to create it. Can someone help to guide me ?

Thanks,
Thomas.

Hi Thomas,

just to make sure I am understanding you right, you would like the above data to produce 4 slices (one for A, B, C and D and give each the size in relation to the amount of different "customer_id" values they had?

If so you can easily create a pie chart, and Use "Terms" aggregation on category for the "Split Slice" bucket, and on the metrics side select "Unique Count" on that customer id field.

Cheers,
Tim

Thank Timroes,

But I want to use count instead of unique count because i want to know exactly how many times customer select a category.

Is there a way to resolve this ?

many thanks,
Thomas.

Could you perhaps provide for the example data above which slices you actually want to have in the pie, and which values should be attached to that slices, since I unfortunately don't understand exactly which order you want to have. Because if you want to see how many times a customer selects a category, that sounds more like you want the customer on the slice level?

The pie chart will have 4 slice (A, B, C , D) :

  • A has value 3
  • B has value 1
  • C has value 1
  • D has value 2

The value of each slice is counted by customer Id.

Here is the data :

[
            {"category": "A", "amount": 28 , { "customer_Id" : 1}},
            {"category": "A", "amount": 12, { "customer_Id" : 2}},
            {"category": "A", "amount": 18, { "customer_Id" : 2}},
            {"category": "A", "amount": 18},
            {"category": "B", "amount": 55, { "customer_Id" : 5}},
            {"category": "C", "amount": 43, { "customer_Id" : 3}},
            {"category": "D", "amount": 91, { "customer_Id" : 4}} ,
            {"category": "D", "amount": 31, { "customer_Id" : 5}}           
     ]

Oh in this case, you just leave the metric aggregation to "Count" (it's default value). That way it will just use the count of individual documents.

Sorry Timroes, I have updated the data, some of the records will not have the object containning customerId.

If I use count , it use the doc_count not the count of customer appearrance.

In this case you could still use count, but just add a filter to the visualization, for customer_id exists. That way you will filter out all documents before aggregating, that doesn't have the customer_id field!

Cheers,
Tim

The problem is that I don't know where to add the filter. Can you please help to create one simple sample with pie chart ?

Many thanks,
Thomas.

Hi,

just use the "Add Filter" button on the top of your screen (below the query bar):

screenshot-20180614-092808

Then select the customer_id field, that you want to be present, and use as an Operator "exists".

That way the data of the visualization will be filtered down and saved with that visualization.

Cheers,
Tim

1 Like

Thank Timrose, It resolves my problem.

I'm glad we could solve it that easily. Please always feel free to come back with further questions (ideally in new threads, if they are about different topics).

Have a nice weekend :sunny:

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