Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

Questions  /  Working with Data  /  SQL

How to normalize data for animated visualizations

Learn how to generate normalized column values for animated (or Torque) visualizations.

Torque animations are based on date- or number-type columns. Our system detects the minimum and maximum values in the column, bins them, and then maps those bins to a range: 0-255. If your number column values exceed 255 you will have to normalize them. One way to normalize a field is by getting its maximum value:

SELECT
  max(column)
FROM
  table_name

Then you can update a new column using the following expression (where 360 is the maximum value in our example column and norm_col is our new column):

UPDATE
  table_name
SET
  norm_col = column*255/360

The final steps are to select the Animated aggregation in your Builder layer’s STYLE panel, select your style settings, set the panel’s toggle to CartoCSS, then replace the Torque aggregation function argument:

-torque-aggregation-function:"avg(norm_col)";