Looker Visualization Components
This skill enables agents to assist users in building custom, high-performance data experiences using Looker's React-based visualization components.
Overview
Looker Visualization Components offer a suite of React primitives to render Looker charts client-side. Unlike iframe-based embedding, these components offer:
- Performance: No iframe overhead; faster rendering and interactions.
- Customization: Deep control over chart configuration and the ability to swap default charts with custom React components.
- Seamless Integration: Fully integrates with Looker's design system (
@looker/components).
1. Installation
Install the core library along with its peer dependencies.
npm install @looker/visualizations @looker/components-data @looker/components @looker/sdk styled-components react react-dom
2. Core Architecture
The system relies on a data-loading layer and a rendering layer.
DataProvider: Context provider that supplies an authenticated Looker SDK instance.Query: Handles data fetching. Supports fetching byquery(ID or slug) ordashboardID.Visualization: Renders the chart using metadata returned by the query.
3. Basic Usage
Wrap your application in DataProvider and use Query to fetch data.
import { Looker40SDK } from '@looker/sdk'
import { DataProvider } from '@looker/components-data'
import { Query, Visualization } from '@looker/visualizations'
const sdk = new Looker40SDK(authSession)
export const AnalyticsDashboard = () => (
<DataProvider sdk={sdk}>
{/* Fetch by Query Slug */}
<Query query="evomfl66xHx1jZk2Hzvv1R">
<Visualization />
</Query>
{/* Fetch by Dashboard ID (fetches the first query on the dashboard) */}
<Query dashboard="123">
<Visualization config={{ type: 'area' }} />
</Query>
</DataProvider>
)
4. Internationalization (i18n)
Localization must be initialized once at the application root.
import { i18nInit, frFR } from '@looker/visualizations'
// Initialize with a specific locale
i18nInit(frFR)
5. Customization & Overrides
Chart Type Overrides
Force a specific chart type regardless of the Looker-saved configuration.
<Visualization config={{ type: 'sparkline', series: [{ color: '#2196f3' }] }} />
Custom Component Mapping
Replace a standard chart type with your own implementation using chartTypeMap.
const CustomTable = ({ data, fields }) => {
return <table>...</table>
}
<Visualization chartTypeMap={{ table: CustomTable }} />
Supported Types
line,area,scatter,sparklinebar,columnpietable(Standard and Pivot support)single_value
6. Advanced Patterns
- Data Transformations: The
Querycomponent automatically applies transformations likesortByDateTime,nullValueZero, andxAxisReversed. - Manual Data Handling: For full control, you can use hooks from
@looker/components-data(e.g.,useQueryData,useVisConfig) directly instead of theQuerycomponent. - Extension Framework: When used inside a Looker Extension, the SDK is typically provided via
ExtensionContext.
7. Troubleshooting
- Theme Errors: Visualization components require a
ThemeProvider. If not provided by the app, they will automatically wrap themselves in aComponentsProvider(Looker's default theme). - Date Measures: Measures of type
dateare currently not supported in standard visualization components. - Missing Peer Deps: Ensure
styled-componentsversion is^5.3.1or higher to avoid context mismatches.