fix: color palette properly applied to bar charts

- ensureStyle: handle empty colors array (use defaults)
- barOptionBuilder: set option.color = style.colors globally
  so ECharts auto-assigns palette colors to all series
- Changing palette in style panel now updates chart colors immediately

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hailin 2026-04-05 02:53:10 -07:00
parent 53669b66b8
commit 1ee9d57222
2 changed files with 2 additions and 1 deletions

View File

@ -34,6 +34,7 @@ function applyCommonStyle(option: Record<string, any>, style: StyleConfig): void
option.legend = { show: false }; option.legend = { show: false };
} }
option.color = style.colors;
option.backgroundColor = style.background.color !== '' ? style.background.color : 'transparent'; option.backgroundColor = style.background.color !== '' ? style.background.color : 'transparent';
if (style.animation.enabled) { if (style.animation.enabled) {

View File

@ -27,7 +27,7 @@ function ensureStyle(style: any): StyleConfig {
if (!style || typeof style !== 'object') return DEFAULT_STYLE; if (!style || typeof style !== 'object') return DEFAULT_STYLE;
return { return {
title: { ...DEFAULT_STYLE.title, ...(style.title ?? {}) }, title: { ...DEFAULT_STYLE.title, ...(style.title ?? {}) },
colors: style.colors ?? DEFAULT_STYLE.colors, colors: (Array.isArray(style.colors) && style.colors.length > 0) ? style.colors : DEFAULT_STYLE.colors,
legend: { ...DEFAULT_STYLE.legend, ...(style.legend ?? {}) }, legend: { ...DEFAULT_STYLE.legend, ...(style.legend ?? {}) },
xAxis: { ...DEFAULT_STYLE.xAxis, ...(style.xAxis ?? {}) }, xAxis: { ...DEFAULT_STYLE.xAxis, ...(style.xAxis ?? {}) },
yAxis: { ...DEFAULT_STYLE.yAxis, ...(style.yAxis ?? {}) }, yAxis: { ...DEFAULT_STYLE.yAxis, ...(style.yAxis ?? {}) },