mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-31 13:58:48 +00:00
完善Legend的formatter对多Serie的支持 (#332)
This commit is contained in:
@@ -76,6 +76,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2024.09.24) 完善`Legend`的`formatter`对多Serie的支持 (#332)
|
||||||
* (2024.09.22) 调整`Documentation`文档显示样式
|
* (2024.09.22) 调整`Documentation`文档显示样式
|
||||||
* (2024.09.09) 增加`numericFormatter`对`date`和`time`的支持
|
* (2024.09.09) 增加`numericFormatter`对`date`和`time`的支持
|
||||||
* (2024.09.03) 完善`AreaStyle`的`origin`参数设置区域填充起始位置
|
* (2024.09.03) 完善`AreaStyle`的`origin`参数设置区域填充起始位置
|
||||||
|
|||||||
@@ -87,11 +87,14 @@ namespace XCharts.Runtime
|
|||||||
ChartHelper.HideAllObject(legendObject);
|
ChartHelper.HideAllObject(legendObject);
|
||||||
if (!legend.show) return;
|
if (!legend.show) return;
|
||||||
var textLimitInitFlag = false;
|
var textLimitInitFlag = false;
|
||||||
|
var isAnySerieColorByData = SeriesHelper.IsAnyColorByDataSerie(chart.series);
|
||||||
for (int i = 0; i < datas.Count; i++)
|
for (int i = 0; i < datas.Count; i++)
|
||||||
{
|
{
|
||||||
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
|
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
|
||||||
string legendName = datas[i];
|
string legendName = datas[i];
|
||||||
var legendContent = GetFormatterContent(legend, i, datas[i]);
|
var serieIndex = isAnySerieColorByData ? 0 : i;
|
||||||
|
var dataIndex = isAnySerieColorByData ? i : 0;
|
||||||
|
var legendContent = GetFormatterContent(legend, dataIndex, datas[i], serieIndex);
|
||||||
if (legend.textLimit.enable)
|
if (legend.textLimit.enable)
|
||||||
legendContent = legend.textLimit.GetLimitContent(legendContent);
|
legendContent = legend.textLimit.GetLimitContent(legendContent);
|
||||||
var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]);
|
var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]);
|
||||||
@@ -158,7 +161,7 @@ namespace XCharts.Runtime
|
|||||||
legend.refreshComponent();
|
legend.refreshComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFormatterContent(Legend legend, int dataIndex, string category)
|
private string GetFormatterContent(Legend legend, int dataIndex, string category, int serieIndex)
|
||||||
{
|
{
|
||||||
#pragma warning disable 0618
|
#pragma warning disable 0618
|
||||||
if (string.IsNullOrEmpty(legend.formatter) && string.IsNullOrEmpty(legend.labelStyle.formatter))
|
if (string.IsNullOrEmpty(legend.formatter) && string.IsNullOrEmpty(legend.labelStyle.formatter))
|
||||||
@@ -168,7 +171,7 @@ namespace XCharts.Runtime
|
|||||||
var formatter = string.IsNullOrEmpty(legend.labelStyle.formatter) ? legend.formatter : legend.labelStyle.formatter;
|
var formatter = string.IsNullOrEmpty(legend.labelStyle.formatter) ? legend.formatter : legend.labelStyle.formatter;
|
||||||
var content = formatter.Replace("{name}", category);
|
var content = formatter.Replace("{name}", category);
|
||||||
content = content.Replace("{value}", category);
|
content = content.Replace("{value}", category);
|
||||||
var serie = chart.GetSerie(0);
|
var serie = chart.GetSerie(serieIndex);
|
||||||
FormatterHelper.ReplaceContent(ref content, dataIndex, legend.labelStyle.numericFormatter, serie, chart, category);
|
FormatterHelper.ReplaceContent(ref content, dataIndex, legend.labelStyle.numericFormatter, serie, chart, category);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,6 +132,21 @@ namespace XCharts.Runtime
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// check if series has any serie which is color by data.
|
||||||
|
/// || 是否有任何一个系列是按数据颜色的。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="series"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsAnyColorByDataSerie(List<Serie> series)
|
||||||
|
{
|
||||||
|
foreach (var serie in series)
|
||||||
|
{
|
||||||
|
if (serie.defaultColorBy == SerieColorBy.Data) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得上一个同堆叠且显示的serie。
|
/// 获得上一个同堆叠且显示的serie。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user