Home > Software engineering >  Application insights - Create a pie chart out of customMeasurements
Application insights - Create a pie chart out of customMeasurements

Time:09-03

I create a custom event whenever a job is processed and use a customMeasurement for every file type I can process.

tc.TrackEvent("File processed",
                metrics: new Dictionary<string, double>{
                  
                    { "HTML", FileType == 0 ? 1 : 0 },
                    { "Excel", FileType == 1 ? 1 : 0},
                    { "CSV", FileType == 2 ? 1 : 0},
                    { "XML" , FileType == 3 ? 1 : 0},
                    ...

I want to create a Log query and show it as a pie chart in my dashboard.

I have reached so far to the query:

customEvents
| project csv=todouble(customMeasurements['CSV']), excel = todouble(customMeasurements['Excel']), html = todouble(customMeasurements['HTML']), xml = todouble(customMeasurements['XML'])
| summarize sum(csv),  sum(excel),  sum(html),  sum(xml)

And this generates the following table:

sum_csv | sum_excel | sum_html | sum_xml
      3 |       230 |      100 |      45

But I need to create a table with the file type summaries and the file type title, such as:

File type | Count
HTML      |  100
XML       |   45
Excel     |  230
CSV       |    3

CodePudding user response:

Using mvexpand bagexpansion=array you can access the columns by using an index. That allows you to perform grouping. So try this:

customEvents
| mvexpand bagexpansion=array customMeasurements
| summarize Count = sum(toint(customMeasurements[1])) by FileType = tostring(customMeasurements[0]) 
| where FileType in ('XML','HTML','Excel','CSV')

output:

enter image description here

  • Related