mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 20:28:46 +00:00
优化Formatter显示
This commit is contained in:
@@ -317,7 +317,7 @@ namespace XCharts
|
|||||||
return dataIndex[0] == index || dataIndex[1] == index;
|
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))
|
if (string.IsNullOrEmpty(m_Formatter))
|
||||||
{
|
{
|
||||||
@@ -331,22 +331,23 @@ namespace XCharts
|
|||||||
var serie = series.GetSerie(i);
|
var serie = series.GetSerie(i);
|
||||||
if (serie.show)
|
if (serie.show)
|
||||||
{
|
{
|
||||||
|
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
|
||||||
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
var serieData = serie.GetSerieData(dataIndex, dataZoom);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
content = content.Replace("{a}", serie.name);
|
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)));
|
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;
|
var percent = serieData.GetData(1) / serie.yTotal * 100;
|
||||||
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
|
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content = content.Replace("{a" + i + "}", serie.name);
|
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)));
|
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;
|
var percent = serieData.GetData(1) / serie.yTotal * 100;
|
||||||
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
|
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
|
||||||
|
|||||||
@@ -239,7 +239,8 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
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();
|
var pos = m_Tooltip.GetContentPos();
|
||||||
if (pos.x + m_Tooltip.width > chartWidth)
|
if (pos.x + m_Tooltip.width > chartWidth)
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
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();
|
var pos = m_Tooltip.GetContentPos();
|
||||||
|
|||||||
Reference in New Issue
Block a user