优化Bar的Tooltip表现

This commit is contained in:
monitor1394
2023-08-22 23:43:33 +08:00
parent 637fde799e
commit 80d596a721
2 changed files with 8 additions and 1 deletions

View File

@@ -449,6 +449,7 @@ namespace XCharts.Runtime
string category = null;
var showCategory = false;
var isTriggerByAxis = false;
var isTriggerByItem = false;
var dataIndex = -1;
tooltip.context.data.param.Clear();
tooltip.context.pointer = chart.pointerPos;
@@ -466,12 +467,18 @@ namespace XCharts.Runtime
else
tooltip.context.data.title = category;
}
else if (tooltip.trigger == Tooltip.Trigger.Item)
{
isTriggerByItem = true;
showCategory = series.Count <= 1;
}
}
for (int i = 0; i < series.Count; i++)
{
var serie = series[i];
if (!serie.show) continue;
if (isTriggerByItem && serie.context.pointerItemDataIndex < 0) continue;
serie.context.isTriggerByAxis = isTriggerByAxis;
if (isTriggerByAxis && dataIndex >= 0 && serie.context.pointerItemDataIndex < 0)
serie.context.pointerItemDataIndex = dataIndex;

View File

@@ -25,7 +25,7 @@ namespace XCharts.Runtime
string marker, string itemFormatter, string numericFormatter, string ignoreDataDefaultContent,
ref List<SerieParams> paramList, ref string title)
{
UpdateCoordSerieParams(ref paramList, ref title, dataIndex, true, category,
UpdateCoordSerieParams(ref paramList, ref title, dataIndex, showCategory, category,
marker, itemFormatter, numericFormatter, ignoreDataDefaultContent);
}