Geo Map Shapes tooltip are not showing the metric value formatted properly


#1

Hi there again, this time I’m facing a new minor issue, the thing is this, I have a Geo Map with some configurations and also an external query that adds a shape layer after the execution is finished. My code looks like the follow one:

// ...
let metric = new cf.Metric('metric', 'sum')
    .label('Metric Custom Label')
    .hideFunction();

cf.provider('Elasticsearch')
    .source(source)
    .rows(...rows)
    .metrics(metric)
    .filters(filters)
    .element(extQueryId)
    .on('execute:stop', (event) => {

        const rows = cf.getVisualization(event.element).get().rows;
        let shapeConfig = {
            'name': 'State',
            'shape': shapesUrl + '/usa-states.json',
            'options': {
                'featureProperty': featureProperty,
                'color': shapeColor,
                'shapeMetrics': [metric],
                'allowClick': options.allowClick || false,
                'showLocation': options.showLocation,
                'shapeOpacity': options.shapeOpacity,
                'shapeOpacityHl': options.borderHighlight,
                'shapeBorderWeightHl': options.shapeBorderWeightHl || 2,
                'shapeBorderColor': 'black',
                'rows': rows
            }
        };

        if (options.dataField) {
            shapeConfig.options.dataField = options.dataField;
        }

        const viz = cf.getVisualization('geo-map-viz-id').get('visual');

        viz.removeShapeLayer(shapeConfig.name);
        viz.addShapeLayer(shapeConfig, event.data);

    })
    .execute();

In my metadata config i have the metric field configured with that type MONEY as bellow:

"metadata": {
    "fields": {
        "metric": {
            "label": "Metric Label",
            "type": "MONEY"
        }
    }
}

When the tooltip is performed the value of the metric is showing as INTEGER instead of MONEY. Any thought about it?

Thanks…


#2

Hi @dmitry, this problem that you are facing is well explained in the Data options section of the Shape layer option documentation. Note that when defining a metric manually, that metric does not contain the field type, which is used to format properly the value of the metric.

For that reason, the shapeMetrics array is best obtained after performing the ChartFactor query using its Aktive object since each metric is enriched with field type used to render tooltips. Thus, you need to change your code by something like this:

const metricsJson = cf.getVisualization(event.element).get().config.metrics;
// ...
"shapeMetrics": [cf.Metric().fromJSON(metricsJson[0])],
// ...

Hope this solve you issue.