Change metrics dinamically


#1

Hi, I have a React app, with some KPIs and bars, but what I need is to change the metrics in real time after a user action, is that possible?


#2

Hey, i think is very easy, why you don’t use a Field selector?, it allows you to change any group or metric in any visualization dynamically:

const charts = ['chart-1', 'chart-2', ....];

cf.provider('Elastic')
    .source('ticket_sales')
    .graph('Field Selector')
    .set('type', ['INTEGER', 'NUMBER', 'MONEY']) // the fields you want to include in the field selector list
    .set('charts', charts) // the charts you want to affect
    .element('v1')
    .execute()


#3

I see, I think is a good option but is not what I want, can we do it without adding more widgets?, I cannot add the field selector in my UI


#4

I understand, well if that’s the case you need to get the visualizations directly, change the properties and run again, let me show you how:

const myViz = cf.getVisualization('your_visualization_id');

// if you need to change the groups
myViz.groupby(newGroupHere);

// if you need to change the metric
myViz.metrics(newMetricHere);

// then just execute your visualization
myViz.execute();

#5

I see, well it works good, and is better for me, thanks for your help