[GNC] Reports: Help normalizing a list of gnc:monetary values
Evelyn Yamanaka
evelyn.yamanaka at gmail.com
Mon Mar 29 07:59:25 EDT 2021
I'm trying to create a stacked bar chart graph where the total for
each period on the x-axis is 100%, so you can easily see trends in
changes in the proportion of individual accounts relative to the
total.
I'm using category-barchart.scm as a starting point, where account
balances are stored as a list of pairs (<account> <balance-list>) in
the variable all-data, and <balance-list> is a list of gnc:monetary
values (or something like that?) for each period on the x-axis.
I can get totals for each period with:
(let ((totals
(map
(lambda (l) (apply gnc:monetary+ l))
(apply zip (map cadr all-data)))))
(set! all-data-totals (list "Total" totals)))
However, I'm not sure how to divide gnc:monetary values by other
gnc:monetary values. I know I can add with:
(for-each
(lambda (d)
(let ((new-data (map gnc:monetary+ (cadr d) (cadr d))))
(set! all-data-new
(append all-data-new
(list (car d) new-data)))))
all-data)
But I'm not sure how to divide. Something like:
(map gnc:monetary/ (cadr all-data-totals) (cadr d))
Of course, "gnc:monetary/" is undefined, and simply using "/" does not
work either. Is there any way to do this? Any help would be appreciated.
Thanks,
E
More information about the gnucash-user
mailing list