diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index 58d2be40..75b71615 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -87,7 +87,7 @@ namespace XCharts.Runtime var active = chart.IsActiveByLegend(datas[i]); var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active); bgColor.a = legend.itemOpacity; - var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, chart.theme, + var item = LegendHelper.AddLegendItem(chart, legend, i, datas[i], legendObject.transform, chart.theme, legendName, bgColor, active, readIndex); legend.SetButton(legendName, item, totalLegend); ChartHelper.ClearEventListener(item.button.gameObject); diff --git a/Runtime/Component/Legend/LegendHelper.cs b/Runtime/Component/Legend/LegendHelper.cs index ed580317..422eb2ab 100644 --- a/Runtime/Component/Legend/LegendHelper.cs +++ b/Runtime/Component/Legend/LegendHelper.cs @@ -6,13 +6,15 @@ namespace XCharts.Runtime { public static class LegendHelper { - public static Color GetContentColor(int legendIndex, Legend legend, ThemeStyle theme, bool active) + public static Color GetContentColor(BaseChart chart, int legendIndex, string legendName, Legend legend, ThemeStyle theme, bool active) { var textStyle = legend.labelStyle.textStyle; if (active) { - if (legend.labelStyle.textStyle.autoColor) return theme.GetColor(legendIndex); - else return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor; + if (legend.labelStyle.textStyle.autoColor) + return SeriesHelper.GetNameColor(chart, legendIndex, legendName); + else + return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor; } else return theme.legend.unableColor; } @@ -31,7 +33,7 @@ namespace XCharts.Runtime else return chart.theme.legend.unableColor; } - public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, + public static LegendItem AddLegendItem(BaseChart chart, Legend legend, int i, string legendName, Transform parent, ThemeStyle theme, string content, Color itemColor, bool active, int legendIndex) { var objName = i + "_" + legendName; @@ -41,7 +43,7 @@ namespace XCharts.Runtime var sizeDelta = new Vector2(100, 30); var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight); var textStyle = legend.labelStyle.textStyle; - var contentColor = GetContentColor(legendIndex, legend, theme, active); + var contentColor = GetContentColor(chart, legendIndex, legendName, legend, theme, active); var objAnchorMin = new Vector2(0, 1); var objAnchorMax = new Vector2(0, 1); diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 70771c55..230af44a 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -226,7 +226,7 @@ namespace XCharts.Runtime { var legend = component as Legend; var iconColor = LegendHelper.GetIconColor(this, legend, legendIndex, legendName, active); - var contentColor = LegendHelper.GetContentColor(legendIndex, legend, m_Theme, active); + var contentColor = LegendHelper.GetContentColor(this, legendIndex, legendName, legend, m_Theme, active); legend.UpdateButtonColor(legendName, iconColor); legend.UpdateContentColor(legendName, contentColor); }