Skip to main content

Overview

Cristalyse provides built-in legend support that automatically generates beautiful legends from your chart’s color mapping data. With just .legend(), you get intelligent symbol generation, smart positioning, and full dark mode compatibility.
New in v1.5.0: Built-in legend support with zero configuration required!

Quick Start

Add a legend to any chart with color mapping in just one line:

Key Features

Zero Configuration

Works automatically with smart defaults - just add .legend()

9 Positioning Options

Flexible positioning: corners, edges, floating with custom coordinates

Smart Symbol Detection

Automatically matches your chart type: squares, circles, lines

Dark Mode Ready

Legend text adapts automatically to light and dark themes

Positioning

Basic Positioning

Control legend placement with the position parameter:

All Position Options

Corner Positions

  • LegendPosition.topLeft
  • LegendPosition.topRight (default)
  • LegendPosition.bottomLeft
  • LegendPosition.bottomRight

Edge Positions

  • LegendPosition.top
  • LegendPosition.bottom
  • LegendPosition.left
  • LegendPosition.right

Free Positioning

  • LegendPosition.floating
  • Set custom coordinates with floatingOffset
  • Perfect for overlay layouts

Visual Examples

Legend appears in the top-right corner with vertical layout.

Floating Legends

New Feature: Floating legends give you complete control over legend positioning with pixel-perfect placement!

Basic Floating Legend

Use floating position for custom positioning:

Styled Floating Legend

Combine floating position with custom styling:

Use Cases for Floating Legends

Perfect for complex dashboards where legends need to float over chart content without taking up layout space.
When you need precise control over legend placement in complex multi-chart layouts.
Programmatically adjust floating position based on screen size or device.

Floating Legend Parameters

Coordinate System: The floatingOffset uses the Flutter coordinate system where Offset(x, y) positions the legend x pixels from the left edge and y pixels from the top edge.

Interactive Legends

New Feature: Interactive legends allow users to click legend items to show/hide data categories!

Basic Interactive Legend

Enable click-to-toggle with one parameter:
Features:
  • Click legend items to show/hide categories
  • Visual feedback: Hidden items appear dimmed with strikethrough
  • Smooth animations: Data fades in/out gracefully
  • Auto-managed state: No additional code needed

External State Management

For advanced control, manage hidden categories externally:

Interactive Legend Parameters

Use Cases

Data Exploration

Users can focus on specific categories by hiding others, making complex charts easier to analyze.

Comparison Analysis

Quickly compare subsets of data by toggling relevant categories on and off.

Presentation Mode

Interactively show/hide data during presentations to highlight key insights.

User Preferences

Save user’s hidden categories to provide personalized dashboard views.

Interactive with Floating Position

Combine interactive and floating for maximum flexibility:
Performance: Data filtering is efficient and only rebuilds the chart when categories are toggled.

Symbol Generation

Legends automatically choose appropriate symbols based on your chart type:
Symbol selection is automatic but can be overridden with custom styling if needed.

Dark Mode Support

Legend text automatically adapts to your chart theme:
Theme Inheritance: Legend text uses theme.axisColor for perfect contrast in any theme.

Custom Styling

Background and Appearance

Add custom styling for professional dashboards:

Text Styling

Customize legend text while preserving theme colors:
Theme Colors: Avoid hardcoding text colors. Let the legend inherit from your theme for proper dark mode support.

All Styling Options

Real-World Examples

Dashboard Analytics

Perfect for executive dashboards with multiple data series:

Mobile-Optimized

Bottom legends work great on mobile devices:

Dark Theme Dashboard

Professional dark mode with custom styling:

Best Practices

  • Use LegendPosition.bottom for mobile layouts
  • Keep symbol sizes readable on small screens
  • Consider horizontal orientation for many categories
  • Let legends inherit theme colors automatically
  • Use subtle backgrounds with transparency
  • Maintain consistent spacing across charts
  • Ensure category names are descriptive
  • Limit legend items to 6-8 for readability
  • Position legends to not obscure important data
  • Rely on automatic theme colors for contrast
  • Test legends in both light and dark modes
  • Ensure sufficient color differentiation

Advanced Usage

Multi-Series Line Charts

Perfect for time-series data with multiple metrics:

Grouped Bar Charts with Custom Colors

Combine custom palettes with legends:

Requirements

Color Mapping Required: Legends only work when you have a color parameter in your .mapping() call.

Migration Guide

From Manual Legends

If you were manually creating legends, you can now use the built-in functionality:

Troubleshooting

Solution: Ensure you have a color parameter in your .mapping() call:
Solution: Don’t override text color - let it inherit from theme:
Solution: Choose a different position or add background:

Y-Axis Titles in Legends

New in v1.13.0: Display Y-axis titles alongside legend entries for multi-axis charts!
For dual-axis charts, show axis titles in the legend to clarify which data series maps to which Y-axis:
Features:
  • Displays Y-axis titles alongside respective data series
  • Improves legend readability for multi-axis charts
  • Helps users understand which metric uses which axis
  • Works with all legend positioning options

Parameters

Pro Tip: Combine showYAxisTitles with descriptive axis titles for maximum clarity in multi-axis charts.

What’s Next?

  • Learn about Custom Themes to create branded chart experiences
  • Explore Interactions to add tooltips and hover effects
  • Check out Export to save charts with legends as SVG files
Pro Tip: Legends work seamlessly with all chart types and export formats. Your exported SVGs will include the positioned legends automatically!