diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md
index e3551017..c00da3c6 100644
--- a/Documentation~/zh/changelog.md
+++ b/Documentation~/zh/changelog.md
@@ -75,6 +75,7 @@ slug: /changelog
## master
+* (2024.07.14) 优化`Axis`的`Time`时间轴的滚动表现
* (2024.07.12) 优化`Label`显示体验
* (2024.07.06) 修复`Chart`在动态创建时背景没有自适应的问题 (#323)
diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs
index cb6dac93..5fe982b9 100644
--- a/Runtime/Component/Axis/AxisHandler.cs
+++ b/Runtime/Component/Axis/AxisHandler.cs
@@ -720,12 +720,6 @@ namespace XCharts
if (AxisHelper.NeedShowSplit(axis))
{
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
- if (axis.IsTime())
- {
- size += 1;
- if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue))
- size += 1;
- }
var tickWidth = axis.axisTick.GetWidth(theme.tickWidth);
var tickColor = axis.axisTick.GetColor(theme.tickColor);
var current = orient == Orient.Horizonal ? startX : startY;
diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs
index 82e5b441..3f090be2 100644
--- a/Runtime/Utilities/DateTimeUtil.cs
+++ b/Runtime/Utilities/DateTimeUtil.cs
@@ -49,6 +49,11 @@ namespace XCharts.Runtime
}
}
+ public static DateTime GetDateTime(double timestamp)
+ {
+ return k_DateTime1970.AddSeconds(timestamp);
+ }
+
public static DateTime GetDateTime(int timestamp)
{
return k_DateTime1970.AddSeconds(timestamp);
@@ -97,6 +102,8 @@ namespace XCharts.Runtime
///
internal static float UpdateTimeAxisDateTimeList(List list, int minTimestamp, int maxTimestamp, int splitNumber)
{
+ var firstValue = list.Count > 0 ? list[0] : 0;
+ var secondValue = list.Count > 1 ? list[1] : 0;
list.Clear();
var range = maxTimestamp - minTimestamp;
if (range <= 0) return 0;
@@ -107,7 +114,8 @@ namespace XCharts.Runtime
if (range >= ONE_YEAR * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_YEAR), 1);
- var dtStart = new DateTime(dtMin.Year + 1, 1, 1);
+ var dtStart = (firstValue == 0 || secondValue == 0) ? new DateTime(dtMin.Year + 1, 1, 1) :
+ (minTimestamp > firstValue ? DateTimeUtil.GetDateTime(secondValue) : DateTimeUtil.GetDateTime(firstValue));
tick = num * 365 * 24 * 3600;
while (dtStart.Ticks < dtMax.Ticks)
{
@@ -118,7 +126,8 @@ namespace XCharts.Runtime
else if (range >= ONE_MONTH * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_MONTH), 1);
- var dtStart = new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1);
+ var dtStart = (firstValue == 0 || secondValue == 0) ? (new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1)) :
+ (minTimestamp > firstValue ? DateTimeUtil.GetDateTime(secondValue) : DateTimeUtil.GetDateTime(firstValue));
tick = num * 30 * 24 * 3600;
while (dtStart.Ticks < dtMax.Ticks)
{