public static Serie AddDefaultTimeGanttSerie(BaseChart chart, string serieName, int dataCount = 0) { var serie = chart.AddSerie(SerieType.Gantt, serieName); serie.showDataName = true; serie.showDataDimension = 2; var timestamp = DateTimeUtil.GetTimestamp(); var now = DateTimeUtil.GetDateTime(timestamp); for (int i = 0; i < dataCount; i++) { var start = timestamp + Random.Range(1, 6) * 3600 * 24; var end = start + Random.Range(1, 10) * 3600 * 24; serie.AddXYData(start, end, "task-" + (i + 1)); } return(serie); }
public string GetFormatterDateTime(int labelIndex, double value) { if (m_FormatterFunction != null) { return(m_FormatterFunction(labelIndex, value, null)); } var timestamp = (int)value; var dateTime = DateTimeUtil.GetDateTime(timestamp); var format = string.IsNullOrEmpty(numericFormatter) ? "yyyy/M/d" : numericFormatter; if (!string.IsNullOrEmpty(m_Formatter)) { var content = m_Formatter; FormatterHelper.ReplaceAxisLabelContent(ref content, dateTime.ToString(format)); return(m_TextLimit.GetLimitContent(content)); } else { var content = dateTime.ToString(format); return(m_TextLimit.GetLimitContent(content)); } }
/// <summary> /// 获得标签显示的名称 /// </summary> /// <param name="index"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <param name="dataZoom"></param> /// <returns></returns> public 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 = axis.boundaryGap ? (dataCount / split) : (dataCount - 1) / split; if (rate == 0) { rate = 1; } int newIndex = index * rate; if (newIndex <= dataCount - 1) { return(axis.axisLabel.GetFormatterContent(showData[newIndex])); } else { if (axis.boundaryGap && coordinateWidth / dataCount > 10) { return(string.Empty); } else { return(axis.axisLabel.GetFormatterContent(showData[dataCount - 1])); } } }