home / skills / toilahuongg / shopify-agents-kit / shopify-polaris-viz

shopify-polaris-viz skill

/.claude/skills/shopify-polaris-viz

This skill helps you build Shopify Polaris Viz charts and themes, enabling accessible, theme-consistent data visualizations in admin dashboards.

npx playbooks add skill toilahuongg/shopify-agents-kit --skill shopify-polaris-viz

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
6.1 KB
---
name: shopify-polaris-viz
description: Guide for creating data visualizations in Shopify Apps using the Polaris Viz library. Use this skill when building charts, graphs, dashboards, or any data visualization components that need to integrate with the Shopify Admin aesthetic. Covers BarChart, LineChart, DonutChart, SparkLineChart, and theming.
---

# Shopify Polaris Viz

Polaris Viz is Shopify's data visualization component library for React. It provides accessible, themeable chart components that match the Shopify Admin visual style.

> **Note**: This library was archived in June 2025. While still functional, Shopify recommends reaching out to support for migration assistance if building new features.

## Installation

```bash
npm install @shopify/polaris-viz
# Required peer dependencies
npm install @shopify/polaris @shopify/polaris-tokens
```

## Setup

Wrap your application with `PolarisVizProvider`:

```jsx
import { PolarisVizProvider } from '@shopify/polaris-viz';
import '@shopify/polaris-viz/build/esm/styles.css';

function App() {
  return (
    <PolarisVizProvider>
      {/* Your app */}
    </PolarisVizProvider>
  );
}
```

## Core Design Principles

1. **One Question Per Chart**: Each visualization should answer a single, specific question
2. **Accuracy First**: Faithfully represent the original dataset
3. **Accessibility**: Support screen readers, color-blind users, and multiple data formats
4. **Consistency**: Use Polaris themes for visual harmony with Shopify Admin

## Available Chart Components

| Component | Use Case | Max Data Points |
|-----------|----------|-----------------|
| `BarChart` | Comparing discrete categories | ~6 categories |
| `SimpleBarChart` | Simple horizontal bars | ~6 categories |
| `LineChart` | Trends over time | 30+ points |
| `SparkLineChart` | Compact inline trends | Any |
| `DonutChart` | Part-to-whole relationships | ~6 segments |
| `StackedAreaChart` | Cumulative trends | 30+ points |
| `FunnelChart` | Conversion funnels | ~6 stages |

## Quick Examples

### Bar Chart

```jsx
import { BarChart } from '@shopify/polaris-viz';

const data = [
  {
    name: 'Sales',
    data: [
      { key: 'Monday', value: 150 },
      { key: 'Tuesday', value: 200 },
      { key: 'Wednesday', value: 175 },
    ],
  },
];

<BarChart data={data} />
```

### Line Chart

```jsx
import { LineChart } from '@shopify/polaris-viz';

const data = [
  {
    name: 'Orders',
    data: [
      { key: 'Jan', value: 100 },
      { key: 'Feb', value: 150 },
      { key: 'Mar', value: 200 },
    ],
  },
];

<LineChart data={data} />
```

### Donut Chart

```jsx
import { DonutChart } from '@shopify/polaris-viz';

const data = [
  { name: 'Direct', data: [{ key: 'Direct', value: 200 }] },
  { name: 'Social', data: [{ key: 'Social', value: 150 }] },
  { name: 'Email', data: [{ key: 'Email', value: 100 }] },
];

<DonutChart data={data} />
```

### Spark Line (Inline Trend)

```jsx
import { SparkLineChart } from '@shopify/polaris-viz';

const data = [
  {
    data: [
      { key: 0, value: 100 },
      { key: 1, value: 150 },
      { key: 2, value: 120 },
      { key: 3, value: 180 },
    ],
  },
];

<SparkLineChart data={data} />
```

## Data Structure

All charts use a consistent `DataSeries` format:

```typescript
interface DataPoint {
  key: string | number;  // X-axis value or category
  value: number | null;  // Y-axis value (null for gaps)
}

interface DataSeries {
  name: string;           // Series label
  data: DataPoint[];      // Array of data points
  color?: string;         // Optional color override
  isComparison?: boolean; // Mark as comparison data (renders grey)
}
```

## Theming

Use the `theme` prop to switch between themes:

```jsx
// Use built-in themes
<BarChart data={data} theme="Light" />
<BarChart data={data} theme="Dark" />

// Or define custom themes in provider
<PolarisVizProvider
  themes={{
    MyBrand: {
      chartContainer: { backgroundColor: '#f9f9f9' },
      seriesColors: { upToEight: ['#5c6ac4', '#47c1bf'] },
    },
  }}
>
  <BarChart data={data} theme="MyBrand" />
</PolarisVizProvider>
```

## Color Guidelines

- **Single series**: Use one consistent color
- **Comparison to past**: Current = purple, Historical = grey
- **Multiple series**: Use contrasting colors (max 4 lines recommended)
- **Positive/Negative**: Green = positive, Red = negative

## Accessibility Requirements

1. **Color contrast**: Ensure sufficient contrast between elements
2. **Screen readers**: Charts render with ARIA attributes
3. **Text alternatives**: Provide data tables as alternative format
4. **No color-only meaning**: Use patterns or labels alongside color

## Common Props

Most chart components accept these props:

| Prop | Type | Description |
|------|------|-------------|
| `data` | `DataSeries[]` | Chart data |
| `theme` | `string` | Theme name |
| `isAnimated` | `boolean` | Enable/disable animations |
| `showLegend` | `boolean` | Show legend |
| `xAxisOptions` | `object` | X-axis configuration |
| `yAxisOptions` | `object` | Y-axis configuration |
| `emptyStateText` | `string` | Text when no data |

## Axis Label Formatting

Follow Shopify's formatting standards:

- **Times**: 12-hour lowercase (12am, 6pm)
- **Days**: Three letters (Sun, Mon)
- **Months**: Three letters (Feb, Mar)
- **Dates**: "10 Apr" format
- **Numbers**: Use "k" for thousands, max 3 digits + decimal + letter

## Anti-Patterns to Avoid

- **DO NOT** exceed 6 categories in bar/donut charts - use tables instead
- **DO NOT** use more than 4 lines in a line chart
- **DO NOT** rely on color alone to convey meaning
- **DO NOT** use edge-to-edge axis lines - keep them within data range
- **DO NOT** mix Polaris Viz with other chart libraries in the same app

## References

- [Chart Components](./references/chart-components.md) - Detailed props and examples for each chart type
- [Theming Guide](./references/theming.md) - Custom theme configuration
- [Data Structures](./references/data-structures.md) - Complete TypeScript interfaces

## External Resources

- [GitHub Repository](https://github.com/Shopify/polaris-viz) (archived)
- [Storybook Documentation](https://polaris-viz.shopify.dev/)
- [Polaris Data Visualization Guidelines](https://polaris-react.shopify.com/design/data-visualizations)

Overview

This skill guides developers in building data visualizations for Shopify Apps using the Polaris Viz library. It focuses on creating accessible, themeable charts that match the Shopify Admin aesthetic and provides practical guidance for BarChart, LineChart, DonutChart, SparkLineChart, and theming. The content emphasizes design principles, data structures, and integration patterns for consistent, accurate charts.

How this skill works

It explains required setup, including wrapping the app with PolarisVizProvider and importing the library styles. The skill describes the DataSeries format used across components, common props, built-in themes, and how to override styles via the provider. It also details component-specific recommendations (max points, ideal use cases) and accessibility and color guidelines to ensure charts remain readable and meaningful.

When to use it

  • Building admin-facing charts that must match Shopify Admin visual style
  • Creating single-question visualizations like trends, comparisons, or part-to-whole breakdowns
  • Embedding compact inline trends (sparklines) inside lists or cards
  • Styling charts to match brand themes while keeping Polaris consistency
  • Needing accessible charts with ARIA attributes and table fallbacks

Best practices

  • Answer one clear question per chart to keep visuals focused
  • Keep bar and donut charts to ~6 categories; use tables for larger categorical sets
  • Limit line charts to 4 series and prefer 30+ points for trend clarity
  • Provide data tables or text alternatives; do not rely on color alone to convey meaning
  • Use built-in themes for consistency and override seriesColors in PolarisVizProvider for brand tweaks
  • Follow Shopify axis formatting (3-letter months/days, 12-hour lowercase times, 'k' number shorthand)

Example use cases

  • Daily sales comparison across a single week using BarChart
  • Monthly orders trend across a quarter with LineChart and hover tooltips
  • Traffic source breakdown via DonutChart for marketing dashboards
  • Inline product conversion trend using SparkLineChart inside a product list
  • Cumulative revenue visualization with StackedAreaChart for multi-category reporting

FAQ

Is Polaris Viz still supported for new projects?

Polaris Viz was archived in mid-2025. It remains functional, but for new long-term projects consult Shopify support for migration options and future guidance.

How do I customize chart colors to match our brand?

Provide a custom theme via PolarisVizProvider and set seriesColors (upToEight). You can also pass color on individual DataSeries for per-series overrides.

What is the required data format?

Use the DataSeries format: each series has a name, an array of { key, value } points, optional color, and isComparison flag for greyed historical data.