Charts
A chart in Quary is a way to visualize data. A chart represents a single visualization. Like models, they are represented by a file but rather than an .sql
file, they are .chart.yaml
file. They are a yaml
file and the contents represent the configuration of the chart. Most of the time you will be using the chart editor to create charts but you can also create them manually. To understand the structure of a chart file, let's look at an example chart file.
Suppose we have a chart file named shifts_by_month_bar.chart.yaml
and it contains the following content:
The name of the chart comes from the name of the file. The name of the file is shifts_by_month_bar.chart.yaml
and the name of the chart is shifts_by_month
.
The chart file has the following three main sections:
reference
: This section contains the source of the chart's data. In this case the source is a model namedshifts_by_month
.description
&tags
: This represents some general metadata.config
: This section contains the configuration of the chart visualization.
Reference section
The reference section contains the source of the chart's data. Charts can point to data in three different ways:
Asset reference
A reference is just a direct reference to another model/snapshot/source in the project. It is what is used in the example and is the most common way to refer to data.
Raw Sql
Raw sql is just what it sounds like, it's a raw query that is sent to the database. It's not templated nor can you refer to other models, nor is it checked at compile time against any sources/models or snapshots that you are referring in it. Rather than reference
, the raw_sql
key is used.
Templated Sql
Raw sql is just what it sounds like, it's a raw query that is sent to the database. But it goes through the quary engine and so you can refer to any other model/snapshot/source in your query with the q.
schema, and it gets templated correctly. The references are also checked at compile time. The following example does the same as the above example for reference as it essentially just selects the model but it gives you the flexibility to do more complex queries just for the chart.
Description and tags
The description and tags work like they do in models. They are just metadata about the chart.
Config section
The config section contains the configuration of the chart visualization. The configuration is specific to the chart plugin being used. The configuration is a yaml
object and the keys and values are specific to the chart plugin. The configuration is what is used to customize the chart. The configuration is specific to the chart plugin being used. The configuration is a yaml
object and the keys and values are specific to the chart plugin. The configuration is what is used to customize the chart. We recommend using the chart editor to create charts as it will help you create the configuration.