优化Formatter显示

This commit is contained in:
monitor1394
2019-09-23 09:41:10 +08:00
parent f708080ed4
commit 9be97bb223
3 changed files with 9 additions and 7 deletions

View File

@@ -317,7 +317,7 @@ namespace XCharts
return dataIndex[0] == index || dataIndex[1] == index;
}
public string GetFormatterContent(int dataIndex, Series series, DataZoom dataZoom = null)
public string GetFormatterContent(int dataIndex, Series series, string category, DataZoom dataZoom = null)
{
if (string.IsNullOrEmpty(m_Formatter))
{
@@ -331,22 +331,23 @@ namespace XCharts
var serie = series.GetSerie(i);
if (serie.show)
{
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
var serieData = serie.GetSerieData(dataIndex, dataZoom);
if (i == 0)
{
content = content.Replace("{a}", serie.name);
content = content.Replace("{b}", serieData.name);
content = content.Replace("{b}", needCategory ? category : serieData.name);
content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1)));
if (serie.type == SerieType.Pie)
//if (serie.type == SerieType.Pie)
{
var percent = serieData.GetData(1) / serie.yTotal * 100;
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
}
content = content.Replace("{a" + i + "}", serie.name);
content = content.Replace("{b" + i + "}", serieData.name);
content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1)));
if (serie.type == SerieType.Pie)
//if (serie.type == SerieType.Pie)
{
var percent = serieData.GetData(1) / serie.yTotal * 100;
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));

View File

@@ -239,7 +239,8 @@ namespace XCharts
}
else
{
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, m_DataZoom));
var category = tempAxis.GetData(index, m_DataZoom);
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series,category, m_DataZoom));
}
var pos = m_Tooltip.GetContentPos();
if (pos.x + m_Tooltip.width > chartWidth)

View File

@@ -593,7 +593,7 @@ namespace XCharts
}
else
{
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series));
m_Tooltip.UpdateContentText(m_Tooltip.GetFormatterContent(index, m_Series, null));
}
var pos = m_Tooltip.GetContentPos();