+1 (726) 227-2971

Advanced Visualization Techniques in Looker

Looker's visualization capabilities are a core feature that brings your data to life, making it easier for users to understand and interact with their data. While Looker offers a plethora of built-in visualization types, it also provides robust capabilities for advanced customizations. This article will delve into how you can create advanced visualizations in Looker, enhancing your data storytelling and the overall user experience.

Built-In Visualization Types

Looker comes with a suite of built-in visualization types, from basic ones like bar charts, line charts, and tables to more advanced visualizations like scatter plots, pie charts, and heat maps. Selecting the right visualization for your data can make it more intuitive and meaningful. Here's how you can specify the visualization type for a query in Looker:

lookml Copy code

orders.view.lkml

view: orders {

...

measure: total_sales { type: sum sql: ${TABLE}.amount ;; drill_fields: [detail*] } } In this LookML code, we have a measure called total_sales. When this measure is used in a query, Looker will default to displaying the results in a table. However, you can easily change this in the Looker UI by clicking the visualization type in the top right corner of the Explore page and selecting a different visualization type.

Custom Color Palettes

One way to make your visualizations more effective is to use custom color palettes. Looker allows you to define custom color palettes that match your company's branding or the theme of your dashboard.

You can set a custom color palette at the model level using the color_palette parameter in a model file. Here's an example:

lookml Copy code

ecommerce.model.lkml

model: ecommerce {

...

color_palette: { label_colors: [ "#D5F5E3", "#D4EFDF", "#A3E4D7", "#A2D9CE", "#92A8D1" ] } } In this example, the color_palette parameter sets the colors used in visualizations in the ecommerce model. The colors are specified in hexadecimal format.

Custom Visualizations

For those use cases where the built-in visualizations don't meet your requirements, Looker supports custom visualizations using JavaScript and the Looker Visualization API.

You can create a custom visualization by creating a JavaScript file that defines how the visualization should render the data it receives. Once you've created your custom visualization, you need to add it to a project in your Looker instance. You can do this by navigating to your project in the Looker IDE, clicking the "Add to Project" button, and selecting "Visualization" from the dropdown menu.

Here's an example of how to create a basic custom visualization:

javascript Copy code looker.plugins.visualizations.add({ id: 'hello_world', label: 'Hello World', options: {}, create: function(element, config) { element.innerHTML = '<h1>Hello, world!</h1>'; }, updateAsync: function(data, element, config, queryResponse, details, doneRendering) { // Do nothing; this visualization doesn't need to update based on the data or configuration doneRendering(); } }); This JavaScript code creates a simple visualization that just displays the text "Hello, world!" When you use this visualization in an Explore, it doesn't matter what data you query; the visualization will always show "Hello, world!"

Leveraging HTML and Liquid for Custom Visualizations

You can also use a combination of HTML and Liquid (a simple templating language) in a LookML model to create custom visualizations. This is especially useful when you want to create a simple custom visualization without writing JavaScript code.

Here's an example of how to use HTML and Liquid to create a custom visualization:

lookml Copy code

orders.view.lkml

view: orders {

...

dimension: total_sales_formatted { type: string sql: ${total_sales} ;; html: "<div style='color: {% if _dimension_value <= 1000 %}red{% else %}green{% endif %};'>${total_sales}</div>" ;; } } In this example, the total_sales_formatted dimension is a string dimension that displays the total_sales measure in a color-coded format. If total_sales is less than or equal to 1000, the text is red; otherwise, it's green.

In summary, Looker provides a robust suite of visualization capabilities. Whether you're using one of the built-in visualization types, customizing the color palette, creating a custom visualization using JavaScript, or leveraging HTML and Liquid, there are myriad ways to make your data more engaging and understandable in Looker.