ColorMap
import { ColorMap } from 'cx/charts'; Copied ColorMap automatically assigns colors from the palette to chart elements. Elements register themselves by name and receive consistent color indices. This is useful when the number of series is dynamic.
<div controller={PageController}>
<Legend />
<Svg style="width: 100%; height: 280px">
<Chart
margin="20 20 40 50"
axes={{
x: { type: NumericAxis },
y: { type: NumericAxis, vertical: true },
}}
>
<Gridlines />
<ColorMap />
<Repeater records={m.series} recordAlias="$record">
<LineGraph
name={m.$record.name}
active={m.$record.active}
data={m.$record.points}
colorMap="lines"
/>
</Repeater>
</Chart>
</Svg>
</div> Series 1
Series 2
Series 3
Series 4
Series 5
How It Works
- Place
ColorMapabove chart elements that need automatic colors - Elements use
colorMap="mapName"to register with a specific color map - ColorMap assigns colors based on element names, distributing them evenly across the palette
- Use
ColorMap.Scopeto isolate multiple color maps in nested charts
Configuration
| Property | Type | Default | Description |
|---|---|---|---|
offset | number | 0 | Starting offset in the color palette. |
step | number | Step between colors. Auto-calculated if not specified. | |
size | number | 16 | Size of the color palette. |
names | string[] | Pre-register names to ensure consistent color assignment. |