Obtaining the percentage growth


#1

Hi there guys, I’m completely new with ChartFactor and I recently hit a rock with something I need to do: I’m trying to build a basic stocks dashboard and need to compare the change (increase/decrease)
between the current month and the previous using percents.

Since I’m working with a custom application (embedding) I think I can work around by calculating the growth by myself (using queries). But I see that ChartFactor does support this type of calculation out of the box. I was going through some examples and I see that you can do that with Comparative metrics, is just that I’m not sure exactly how to accomplish what I’m trying to do.


#2

Hi @brian, what you are looking for is the growth rate, you can see the documentation for examples. But basically the key points of this metric (comparative metric) are with() and the using() methods:

cf.CompareMetric('metric_name', 'sum')
// That's how you tell you want the growth rate
.rate('growth') 
// The time in the pass you want to compare
//  against, in your case is -1 month
.with('-1 month') 
// The time field name that, when applied 
// as filter, will calculate the growth rate 
.using('saletime')

If you apply a filter for february 2020, since you have -1 month in the .with() method, the provider will bring the metric value also for january 2020 and then it will calculate the rate automatically for you. I hope its clear.


#3

Thank you @eduardo, is it possible to do it without filters with a pre-fixed .with() or something? Like for example show by default the growth rate between the prev and current month? Sometimes I accidentally remove the filter from the interaction manager and I know our users will.


#4

Pass your filters directly with .filters(yourTimeFilter) to your visualization.


#5

Better is to use staticFilters(timeFilter). By using filters(timeFilter) the Interaction Manager will delete the filter when the user manually removes it. With staticFilters you ensure the visualization will always has it.


#6

Thanks! Yes the staticFilters did the work. The best thing is that it will be overwritten if a filter with the same field (in this case my time filter) is applied but as soon as I remove it it goes back to the static value