Skip to content

Custom Metadata

As we mentioned before, the metadata is retrieved directly from the provider, but sometimes this metadata won't fit with whatever we want to show in a set of visuals. For example we can have a field named pricepaid, which represents a monetary value, but the information coming from the provider says that this field is of type "NUMBER". Since fields with type "MONEY" are formatted with the "$" sign, the value for pricepaid won't be displayed as it should:

CM1

Also note the X Axis label, it could be more expressive. We can change almost any field metadata coming from the provider with our own like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
var providers = [ {
        name:'Elasticsearch',
        provider:'elasticsearch',
        url:'https://chartfactor.com/elastic/',
        metadata: {
            'ticket_sales': {
                'fields': {
                    'catname': { 'label': 'Category Name' },
                    'pricepaid': { 'label': 'Price Paid', 'type': 'MONEY' }
                }
            }
        }
    }
]

// Set the data provider to chartfactor
cf.setProviders(providers);

myChart = cf.provider('Elasticsearch')....execute();

Note

In the metadata example above, 'ticket_sales' is the source name.

After this, we can see how the tooltip's format has changed as well as the labels for the Y and X axis respectively:

CM2

Custom Data Format

As we saw in the previous example, the format to change any field information is the following:

1
2
3
4
5
6
7
8
9
var customData = {
    'source_name_1': {
        'fields': {
            'field1': { 'label': 'My Custom Label' },
            'field2': { 'type': 'ATTRIBUTE | INTEGER | NUMBER | MONEY | PERCENT | TIME' }
        }
    },
    'source_name_2': { ... }
})

What information can be changed?

We can change any information available from the provider's metadata. In next iterations, additional metadata will be included to add more flexibility to ChartFactor such as custom formatters for fields. We can access the current provider's metadata like this:

1
elasticProv._metadata