Use the palette attribute to apply color schemes to charts. Choose from built-in palettes or define custom palettes with label/value matching.
Reference any of these palettes by name using the palette attribute:
Fixed lists of distinct colors. Colors cycle if you have more data elements than palette colors.
Two-color gradients. Colors are interpolated based on the number of data elements.
Three-color gradients with a neutral midpoint. Great for data with a meaningful center (e.g., positive/negative).
Add the palette attribute to any chart:
<dc-chart width="500" height="350" palette="category10">
<dc-title>Quarterly Sales</dc-title>
<dc-bar value="10" label="Q1"></dc-bar>
<dc-bar value="25" label="Q2"></dc-bar>
<dc-bar value="15" label="Q3"></dc-bar>
<dc-bar value="40" label="Q4"></dc-bar>
<dc-legend></dc-legend>
</dc-chart>
<dc-funnel-chart width="500" height="350" palette="cool-to-warm">
<dc-title>Sales Funnel</dc-title>
<dc-funnel-stage value="1000" label="Visitors"></dc-funnel-stage>
<dc-funnel-stage value="600" label="Leads"></dc-funnel-stage>
<dc-funnel-stage value="200" label="Opportunities"></dc-funnel-stage>
<dc-funnel-stage value="80" label="Customers"></dc-funnel-stage>
</dc-funnel-chart>
Define reusable color schemes with <dc-palette> for label matching and value-range matching:
<dc-palette id="brand-colors">
<dc-fill label="Revenue" fill="#2563eb"></dc-fill>
<dc-fill label="Expenses" fill="#dc2626"></dc-fill>
<dc-fill label="Profit" fill="#16a34a"></dc-fill>
</dc-palette>
<dc-chart palette="brand-colors" width="500" height="350">
<dc-title>Q4 Financial Summary</dc-title>
<dc-bar value="120" label="Revenue"></dc-bar>
<dc-bar value="80" label="Expenses"></dc-bar>
<dc-bar value="40" label="Profit"></dc-bar>
<dc-legend></dc-legend>
</dc-chart>
<dc-palette id="performance-thresholds">
<dc-fill max-value="30" fill="#fee2e2"></dc-fill>
<dc-fill min-value="30" max-value="70" fill="#fef3c7"></dc-fill>
<dc-fill min-value="70" fill="#dcfce7"></dc-fill>
</dc-palette>
<dc-chart palette="performance-thresholds" width="500" height="350">
<dc-title>Team Performance Scores</dc-title>
<dc-bar value="25" label="Team A"></dc-bar>
<dc-bar value="55" label="Team B"></dc-bar>
<dc-bar value="85" label="Team C"></dc-bar>
<dc-bar value="42" label="Team D"></dc-bar>
</dc-chart>
A common use case for value-range palettes is coloring positive values one color and negative values another:
<dc-palette id="pos-neg">
<dc-fill max-value="0" fill="#F44336"></dc-fill>
<dc-fill min-value="0" fill="#4CAF50"></dc-fill>
</dc-palette>
<dc-chart palette="pos-neg" width="500" height="350">
<dc-title>Monthly Profit/Loss</dc-title>
<dc-bar value="35" label="Jan"></dc-bar>
<dc-bar value="-20" label="Feb"></dc-bar>
<dc-bar value="50" label="Mar"></dc-bar>
<dc-bar value="-10" label="Apr"></dc-bar>
<dc-bar value="25" label="May"></dc-bar>
<dc-bar value="-30" label="Jun"></dc-bar>
</dc-chart>
The palette uses two <dc-fill> rules with value boundaries at zero:
max-value="0" matches any value ≤ 0 (negative values)min-value="0" matches any value ≥ 0 (positive values)When a bar has a negative value, it matches the first rule and gets red. When positive, it matches the second rule and gets green.
Priority: Value matching takes precedence over label matching, allowing you to override colors based on thresholds.
Colors are resolved in this priority order (highest to lowest):
fill or stroke on individual elements (see Element Colors)min-value/max-value from custom palettelabel from custom paletteUser-defined <dc-palette> elements take precedence over built-in palettes with the same name.