Overview
Scales in Cristalyse transform data values to visual positions or dimensions on a chart. They handle both continuous and categorical data, ensuring intuitive and precise data representation.Linear Scales
Linear scales map continuous data to a range, such as pixels:Axis Titles
New in v1.10.0: Add descriptive titles to your axes for better data context!
title parameter to display descriptive axis labels:
- Smart Positioning: Automatically positioned with optimal spacing
- Rotated Text: Y-axis titles rotate -90°, Y2-axis titles rotate +90°
- Theme-Aware: Inherits text style from theme with slightly larger font
- Optional: Only renders when provided (fully backward compatible)
Configuration
- Domain: Data range mapped to chart space.
- Range: Pixel space where the data is plotted.
- Limits: Optional
min/maxparameters to constrain the displayed scale range. - Title: Optional descriptive label for the axis (v1.10.0+)
- Invertible: Values can map back to the data space.
Scale Limits and Data Filtering
Usemin and max parameters to control scale behavior:
Ordinal Scales
Ordinal scales map categorical data to discrete locations:Configuration
- Domain: List of categories.
- Range: Space for categories to be displayed.
- BandWidth: Space allocated to each category.
- Title: Optional descriptive label for the axis (v1.10.0+)
Color Scales
Color scales are used to encode data using color gradients:Size Scales
Size scales map data values to sizes, useful for scatter plots:Label Formatting
Transform axis labels by passing a callback to thelabels parameter on any axis scale that takes any number and returns a string.
Direct NumberFormat Usage
For simple cases, you can useNumberFormat from Dart’s intl package:
Custom Callbacks for Advanced Cases
When you need custom logic beyond NumberFormat, use a factory pattern to create a callback based on that logic.Conditional Formatting (Value-Based Logic)
Chart-Optimized Formatting (Clean Integers)
Business Logic Formatting
Tick Configuration
New in v1.14.0: Control how tick marks and labels are generated on your axes!
Explicit Tick Specification
Provide your own tick positions for precise control:- Industry-standard reference points (e.g., freezing point at 0°C)
- Domain-specific intervals (e.g., percentiles at 25, 50, 75)
- Matching ticks across multiple related charts
Simple Linear Ticking
Generate evenly-spaced ticks instead of using Wilkinson’s algorithm:- Wilkinson’s Algorithm (default): Intelligently chooses “nice” numbers for human-readable labels. Tick intervals vary based on data range (e.g., 10, 25, 50, 100).
- Simple Linear: Always generates evenly-spaced ticks. Tick interval is constant based on the scale range divided by number of ticks.
- Time-based charts where consistent intervals matter (e.g., hourly or daily splits)
- Scientific/technical charts where precision is preferred over “niceness”
- When you need predictable, uniform spacing
Dual-Axis Example
Scale Customization
Customize scales to fit your data representation needs:Best Practices
Scaling Data
- Choose linear scales for time-series and numerical data.
- Use ordinal scales for categorical data like labels or segments.
- Opt for consistent scale units across charts.
Performance
- Ensure domain and range values are correctly configured.
- Minimize dynamic scale recalculation for better performance.
- Use scale inversions in interactive applications for better feedback.
Advanced Usage
Dual Axis Charts
Implement dual axes for complex comparisons:Conditional Scales
Dynamically adjust scales based on data:Example Gallery
Time-Series Analysis
Vivid depiction of temporal trends and changes over time.
Categorical Comparison
Clear comparison of discrete categories using ordinal scaling.
Revenue vs. Conversion
Dual-axis chart illustrating financial performance metrics.
Dynamic Data Scaling
Interactive scales adapting to real-time data changes.
Next Steps
Data Mapping
Effective data field-to-visual property mapping techniques.
Custom Themes
Create custom themes to match brand identity.
Performance Scaling
Optimize visual performance with tailored scaling strategies.
Interactions
Engage users with interactive scaled charts.
Technical Details
Review the source code behind scale transformations and extend as needed within thescale.dart file.