Passing constant to override chart config dynamically

Hello community!

I'm trying to customise one of my visualisations dynamically with the use of a parameter and a constant.

The parameter controls whether the user wants to see whole numbers or decimal numbers. The parameter is set as a dashboard level filter. The constant encapsulates that logic so that it can be applied in particular components, such as the legend of the pie chart. Right now, the legend of the pie chart defaults to 2 decimal cases, but we actually want it to change to whole numbers when the parameter selection also changes to whole numbers.

I have managed to override the pie chart configuration in a static fashion by introducing this attribute in my dashboard file:

advanced_vis_config: |-
{legend: {labelFormat: '<span class=\"highcharts-data-label\">{name} {percentage:.0f}%</span>'}}

But attempting to call the parameter doesn't render the actual values that are behind the constant:

advanced_vis_config: |-
{"@{decimal_parameter_legend}"

This is how the constant is defined:

constant: decimal_precision_legend {
value: "
{% if reviews.decimal_precision_parameter._parameter_value == 'show_two_decimal_places' %}
{legend: {labelFormat: '<span class=\"highcharts-data-label\">{name} {percentage:.2f}%</span>'}}
{% else %}
{legend: {labelFormat: '<span class=\"highcharts-data-label\">{name} {percentage:.0f}%</span>'}}
{% endif %}
"
}

What am I doing wrong?

Thanks,

Daniel

1 1 85
1 REPLY 1

Hey Daniel, cool use case here! 

There isn't a way to dynamically update visualization configurations using parameters, etc. This is a cool use case though, and I definitely recommend creating a feature request in the product!