mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 22:40:10 +00:00
增加Axis类目轴数据为空时的默认显示支持。
This commit is contained in:
@@ -422,11 +422,12 @@ namespace XCharts
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public float GetDataWidth(float coordinateWidth, DataZoom dataZoom)
|
||||
public float GetDataWidth(float coordinateWidth, int dataCount, DataZoom dataZoom)
|
||||
{
|
||||
var dataCount = GetDataNumber(dataZoom);
|
||||
int segment = (m_BoundaryGap ? dataCount : dataCount - 1);
|
||||
segment = segment <= 0 ? 1 : segment;
|
||||
if (dataCount < 1) dataCount = 1;
|
||||
var categoryCount = GetDataNumber(dataZoom);
|
||||
int segment = (m_BoundaryGap ? categoryCount : categoryCount - 1);
|
||||
segment = segment <= 0 ? dataCount : segment;
|
||||
return coordinateWidth / segment;
|
||||
}
|
||||
|
||||
@@ -578,6 +579,13 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
internal bool NeedShowSplit()
|
||||
{
|
||||
if (!show) return false;
|
||||
if (IsCategory() && data.Count <= 0) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调整最大最小值
|
||||
/// </summary>
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
var isCartesian = IsValue();
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
@@ -189,7 +190,7 @@ namespace XCharts
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = coordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
@@ -201,7 +202,7 @@ namespace XCharts
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = coordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
@@ -218,7 +219,7 @@ namespace XCharts
|
||||
m_Tooltip.yValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = coordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
@@ -236,7 +237,7 @@ namespace XCharts
|
||||
m_Tooltip.xValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = coordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
@@ -328,7 +329,7 @@ namespace XCharts
|
||||
sb.Append("\n")
|
||||
.Append("<color=#").Append(m_ThemeInfo.GetColorStr(i)).Append(">● </color>")
|
||||
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
||||
.Append(ChartCached.FloatToStr(yValue,0,m_Tooltip.forceENotation));
|
||||
.Append(ChartCached.FloatToStr(yValue, 0, m_Tooltip.forceENotation));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -929,7 +930,7 @@ namespace XCharts
|
||||
|
||||
private void DrawXAxisTickAndSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis)
|
||||
{
|
||||
if (xAxis.show)
|
||||
if (xAxis.NeedShowSplit())
|
||||
{
|
||||
var size = xAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateX;
|
||||
@@ -1115,13 +1116,13 @@ namespace XCharts
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
|
||||
if (m_Tooltip.type == Tooltip.Type.None) return;
|
||||
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
float splitWidth = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float splitWidth = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
@@ -1159,13 +1160,13 @@ namespace XCharts
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
|
||||
if (m_Tooltip.type == Tooltip.Type.None) return;
|
||||
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
var yAxis = m_YAxises[i];
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
float splitWidth = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace XCharts
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
|
||||
float categoryWidth = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
float categoryWidth = yAxis.GetDataWidth(coordinateHeight,showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
@@ -30,7 +31,7 @@ namespace XCharts
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
|
||||
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
@@ -131,7 +132,7 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
|
||||
float categoryWidth = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float categoryWidth = xAxis.GetDataWidth(coordinateWidth,showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace XCharts
|
||||
var zeroPos = new Vector3(coordinateX, coordinateY + yAxis.zeroYOffset);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWidth, showData.Count, m_DataZoom);
|
||||
float startX = coordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
@@ -330,7 +330,7 @@ namespace XCharts
|
||||
var zeroPos = new Vector3(coordinateX + xAxis.zeroXOffset, coordinateY);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHeight, showData.Count, m_DataZoom);
|
||||
float startY = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace XCharts
|
||||
if (f == 0) valueDic[value] = forceE ? value.ToString("E") : value.ToString();
|
||||
else if (f == 1) valueDic[value] = value.ToString("f1");
|
||||
else if (f == 2) valueDic[value] = value.ToString("f2");
|
||||
else valueDic[value] = (f > 3 || forceE) ? value.ToString("E1") : value.ToString(GetFn(f));
|
||||
else valueDic[value] = (f > 3 || forceE) ? value.ToString("E0") : value.ToString(GetFn(f));
|
||||
return valueDic[value];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user