/// <summary> /// 获得标签显示的名称 /// </summary> /// <param name="index"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <param name="dataZoom"></param> /// <returns></returns> internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue, DataZoom dataZoom, bool forcePercent) { int split = GetSplitNumber(axis, coordinateWidth, dataZoom); if (axis.type == Axis.AxisType.Value) { if (minValue == 0 && maxValue == 0) { return(string.Empty); } var value = 0f; if (forcePercent) { maxValue = 100; } if (axis.interval > 0) { if (index == split) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = minValue + (maxValue - minValue) * index / split; if (!axis.clockwise && value != minValue) { value = maxValue - value; } } if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } if (forcePercent) { return(string.Format("{0}%", (int)value)); } else { return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue)); } } else if (axis.type == Axis.AxisType.Log) { float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) : Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index); if (axis.inverse) { value = -value; minValue = -minValue; maxValue = -maxValue; } return(axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true)); } else if (axis.type == Axis.AxisType.Time) { if (minValue == 0 && maxValue == 0) { return(string.Empty); } var value = 0f; if (axis.interval > 0) { if (index == split) { value = maxValue; } else { value = minValue + index * axis.interval; } } else { value = minValue + (maxValue - minValue) * index / split; } var timestamp = (int)value; var dateTime = DateTimeUtil.GetDateTime(timestamp); return(axis.axisLabel.GetFormatterDateTime(dateTime)); } var showData = axis.GetDataList(dataZoom); int dataCount = showData.Count; if (dataCount <= 0) { return(""); } int rate = Mathf.RoundToInt(dataCount * 1f / split); int newIndex = index * rate; if (newIndex <= dataCount - 1) { return(axis.axisLabel.GetFormatterContent(showData[newIndex])); } else { if (rate == 1) { return(string.Empty); } else if (axis.boundaryGap && coordinateWidth / dataCount > 10) { return(string.Empty); } else { if ((index - 1) * rate > dataCount - 1) { return(string.Empty); } else { return(axis.axisLabel.GetFormatterContent(showData[dataCount - 1])); } } } }