Question
I'm creating a chart. I have a table with the following fields:
I want to create 3 line charts that show the dynamics of one of the metrics (visible, traffic, keywords) for each domain by date. So, I need to somehow pass the domains into the JSON template.
Answer
In Totum charts, there are dynamic parameters datasets
passed in the main row
: field: "datasets_label" = $list_d_labels
The key in row
is specified as datasets_PARAM
.
Code in the chart:
=: rowCreate(field: "labels" = $list_labels; field: "values" = $list_values; field: "datasets_label" = $list_d_labels)
list_labels: $dates
list_d_labels: $sites
list_values: listReplace(list: $sites; action: $sites_data; value: "sites_data")
sites_data: $create_data[[$column]]
column: $#sites_data
~create_data: listReplace(list: $dates; action: $val; value: "date")
val: rowCreateByLists(keys: $keysList; values: $valuesList)
keysList: $sites
valuesList: listReplace(list: $sites; action: $keywords; value: "site")
keywords: select(table: $#ntn; field: 'keywords'; where: 'site' = $#site; where: 'date' = $#date)
~dates: listUniq(list: $list_dates)
list_dates: selectList(table: $#ntn; field: 'date'; order: 'date' asc)
~sites: listUniq(list: $list_sites)
list_sites: selectList(table: $#ntn; field: 'site'; order: 'site' asc)