how to display total record by group in graph chart

i want to display the number of records in a particular graph chart. but the api could only get records by filters.

Any ideas, please? I can not query the record matching with group by condition.

Hi, Nguyễn Hiệp

You can get the number of records with the following JavaScript.

jQuery.noConflict();
(function($) {
"use strict";
kintone.events.on("app.report.show", function(event) {
var query = kintone.app.getQueryCondition();
var appId = kintone.app.getId();
var params = { app: appId, query: query + ' limit 1', fields: ['$id'], totalCount: true };
var strUrl = kintone.api.url('/k/v1/records', true);
kintone.api(strUrl, 'GET', params).then(function(resp) {
var totalCount = resp.totalCount;
$('#ttl-div').remove();
$('.filter-contents-gaia.subtotal-chartType-gaia').append('<div id="ttl-div" style="margin-left:20px;display:inline-block;">Total Records: ' + totalCount + '</div>');
});
return event;
});
})(jQuery);

Sorry, I overlooked the condition. (Group by condition)
I have no good idea.

thank you for your response :slight_smile:
i could also get the total records by filter condition (query condition) but stucked in “group by” condition. I 've recognized that there’s a “groups” param in the report(graph) page url looks like :

https://subdomain.kintone.com/k/35/report?q&groups= some_id &summaries=COUNT&sort=s0%3Adesc&chart=pie

i thought it 's related to a field (the field that 's used to be the group by condition), so i intended to use field_code to filter the total records , but i couldn’t get the relevant here, is there any way to derive field_code from group param?

I know field-no of group param.

field-no is a unique number assigned to the fieldcode.
fnnnnnnn manual convert to fieldcode. The conversion method is not disclosed.
You can found field-no on DOM of detail show page by browser developer tool.

 

example.

param decode base64.

decodeURIComponent(‘report?q&groups=f5346135%3AYEAR_MONTH_DAY&summaries=COUNT&sort=g0%3Aasc&chart=pie’)
->
“report?q&groups=f5346135:YEAR_MONTH_DAY&summaries=COUNT&sort=g0:asc&chart=pie”

field-no: 5346135

Check field-no:5346135 on detail show page.

Then in conclusion, the only way to get field_id is from DOM content isn’t it?
i may try to get total record directly from DOM content of the chart if there isn’t any better choices

Aw, thank you for your help :slight_smile:

You can find a conversion method by examining global variables.
However, since it is not an official method, there is a risk of being changed.

do you know which method it’s ?

i’ve examined the global object (Cybozu/ kintone/ …) in awhile but still couldn’t find the conversion method :frowning:

Let’s looking for it yourself. :slight_smile:

 

anyway, thank you so much (y)

thank you!