mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 09:50:15 +00:00
增加Chart的useUtc参数设置显示时间是否用UTC时间
This commit is contained in:
@@ -85,7 +85,7 @@ namespace XCharts.Runtime
|
||||
float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i + 1, null);
|
||||
bool inside = axis.axisLabel.inside;
|
||||
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
|
||||
null, isPercentStack);
|
||||
null, isPercentStack, chart.useUtc);
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
|
||||
new Vector2(scaleAngle, txtHig), axis,
|
||||
chart.theme.axis, labelName, Color.clear);
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace XCharts
|
||||
if (context.labelObjectList[i] != null)
|
||||
{
|
||||
var index = i < showData.Count ? showData[i].index : i;
|
||||
var text = AxisHelper.GetLabelName(axis, coordinateWidth, index, destMinValue, destMaxValue, dataZoom, forcePercent, i);
|
||||
var text = AxisHelper.GetLabelName(axis, coordinateWidth, index, destMinValue, destMaxValue, dataZoom, forcePercent, chart.useUtc, i);
|
||||
context.labelObjectList[i].SetText(text);
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,7 @@ namespace XCharts
|
||||
{
|
||||
if (context.labelObjectList[i] != null)
|
||||
{
|
||||
var text = AxisHelper.GetLabelName(axis, coordinateWidth, i, destMinValue, destMaxValue, dataZoom, forcePercent);
|
||||
var text = AxisHelper.GetLabelName(axis, coordinateWidth, i, destMinValue, destMaxValue, dataZoom, forcePercent, chart.useUtc);
|
||||
context.labelObjectList[i].SetText(text);
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ namespace XCharts
|
||||
{
|
||||
var lastCount = axis.context.labelValueList.Count;
|
||||
axis.context.tickValue = DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList,
|
||||
axis.context.minValue, axis.context.maxValue, axis.splitNumber, axis.ceilRate);
|
||||
axis.context.minValue, axis.context.maxValue, axis.splitNumber, axis.ceilRate, !chart.useUtc);
|
||||
|
||||
if (axis.context.labelValueList.Count != lastCount)
|
||||
axis.SetAllDirty();
|
||||
@@ -454,7 +454,7 @@ namespace XCharts
|
||||
label.SetTextActive(false);
|
||||
return;
|
||||
}
|
||||
if(content == null)
|
||||
if (content == null)
|
||||
{
|
||||
content = label.text.GetText();
|
||||
}
|
||||
@@ -465,12 +465,12 @@ namespace XCharts
|
||||
if (i == 0)
|
||||
{
|
||||
var dist = GetLabelPosition(0, 1).x - pos.x;
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i, 0, content) && dist > label.text.GetPreferredWidth());
|
||||
}
|
||||
else if (i == axis.context.labelValueList.Count - 1)
|
||||
{
|
||||
var dist = pos.x - GetLabelPosition(0, i - 1).x;
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i, 0, content) && dist > label.text.GetPreferredWidth());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -478,12 +478,12 @@ namespace XCharts
|
||||
if (i == 0)
|
||||
{
|
||||
var dist = GetLabelPosition(0, 1).y - pos.y;
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i, 0, content) && dist > label.text.GetPreferredHeight());
|
||||
}
|
||||
else if (i == axis.context.labelValueList.Count - 1)
|
||||
{
|
||||
var dist = pos.y - GetLabelPosition(0, i - 1).y;
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight());
|
||||
label.SetTextActive(axis.IsNeedShowLabel(i, 0, content) && dist > label.text.GetPreferredHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -552,7 +552,7 @@ namespace XCharts
|
||||
var labelName = AxisHelper.GetLabelName(axis, axisLength, sortIndex,
|
||||
axis.context.destMinValue,
|
||||
axis.context.destMaxValue,
|
||||
dataZoom, isPercentStack, i);
|
||||
dataZoom, isPercentStack, chart.useUtc, i);
|
||||
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
|
||||
ChartCached.GetAxisLabelName(i),
|
||||
@@ -671,7 +671,7 @@ namespace XCharts
|
||||
var labelName = AxisHelper.GetLabelName(axis, axisLength, sortIndex,
|
||||
axis.context.destMinValue,
|
||||
axis.context.destMaxValue,
|
||||
dataZoom, isPercentStack, i);
|
||||
dataZoom, isPercentStack, chart.useUtc, i);
|
||||
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
|
||||
ChartCached.GetAxisLabelName(i),
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace XCharts.Runtime
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetLabelName(Axis axis, float coordinateWidth, int index, double minValue, double maxValue,
|
||||
DataZoom dataZoom, bool forcePercent, int sortIndex = -1)
|
||||
DataZoom dataZoom, bool forcePercent, bool useUtc, int sortIndex = -1)
|
||||
{
|
||||
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
|
||||
if (sortIndex == -1) sortIndex = index;
|
||||
@@ -161,7 +161,7 @@ namespace XCharts.Runtime
|
||||
return string.Empty;
|
||||
|
||||
var value = axis.GetLabelValue(index);
|
||||
return axis.axisLabel.GetFormatterDateTime(sortIndex, axis.context.labelValueList.Count, value, minValue, maxValue);
|
||||
return axis.axisLabel.GetFormatterDateTime(sortIndex, axis.context.labelValueList.Count, value, minValue, maxValue, !useUtc);
|
||||
}
|
||||
var showData = axis.GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace XCharts.Runtime
|
||||
var inside = axis.axisLabel.inside;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
|
||||
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.context.minValue, axis.context.maxValue,
|
||||
null, isPercentStack);
|
||||
null, isPercentStack, chart.useUtc);
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
|
||||
new Vector2(labelWidth, txtHig), axis, chart.theme.axis, labelName, Color.clear);
|
||||
|
||||
|
||||
@@ -485,10 +485,10 @@ namespace XCharts.Runtime
|
||||
|
||||
private static bool isDateFormatter = false;
|
||||
private static string newFormatter = null;
|
||||
public string GetFormatterDateTime(int labelIndex, int totalIndex, double value, double minValue, double maxValue)
|
||||
public string GetFormatterDateTime(int labelIndex, int totalIndex, double value, double minValue, double maxValue, bool local)
|
||||
{
|
||||
var timestamp = value;
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp);
|
||||
var dateTime = DateTimeUtil.GetDateTime(timestamp, local);
|
||||
var dateString = string.Empty;
|
||||
if (string.IsNullOrEmpty(numericFormatter) || numericFormatter.Equals("f2"))
|
||||
{
|
||||
@@ -501,7 +501,7 @@ namespace XCharts.Runtime
|
||||
if (DateTimeUtil.IsDateOrTimeRegex(numericFormatter, ref isDateFormatter, ref newFormatter))
|
||||
{
|
||||
if (isDateFormatter)
|
||||
dateString = ChartCached.NumberToDateStr(timestamp, newFormatter);
|
||||
dateString = ChartCached.NumberToDateStr(timestamp, newFormatter, local);
|
||||
else
|
||||
dateString = ChartCached.NumberToTimeStr(timestamp, newFormatter);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
else if (axis.IsTime())
|
||||
{
|
||||
label.SetText(axis.indicatorLabel.GetFormatterDateTime(0, 0, axis.context.pointerValue, axis.context.minValue, axis.context.maxValue));
|
||||
label.SetText(axis.indicatorLabel.GetFormatterDateTime(0, 0, axis.context.pointerValue, axis.context.minValue, axis.context.maxValue, !chart.useUtc));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -356,7 +356,7 @@ namespace XCharts.Runtime
|
||||
if (isTriggerAxis)
|
||||
{
|
||||
var index = serie.context.dataZoomStartIndex + (int)yAxis.context.pointerValue;
|
||||
if(serie.useSortData) index = yAxis.context.sortedDataIndices[index];
|
||||
if (serie.useSortData) index = yAxis.context.sortedDataIndices[index];
|
||||
serie.context.pointerEnter = true;
|
||||
serie.context.pointerAxisDataIndexs.Add(index);
|
||||
serie.context.pointerItemDataIndex = index;
|
||||
@@ -376,7 +376,7 @@ namespace XCharts.Runtime
|
||||
if (isTriggerAxis)
|
||||
{
|
||||
var index = serie.context.dataZoomStartIndex + (int)xAxis.context.pointerValue;
|
||||
if(serie.useSortData) index = xAxis.context.sortedDataIndices[index];
|
||||
if (serie.useSortData) index = xAxis.context.sortedDataIndices[index];
|
||||
if (chart.isTriggerOnClick)
|
||||
{
|
||||
if (serie.insertDataToHead)
|
||||
@@ -616,7 +616,7 @@ namespace XCharts.Runtime
|
||||
var serieData = serie.GetSerieData(serie.context.pointerItemDataIndex);
|
||||
if (serieData != null)
|
||||
{
|
||||
tooltip.context.data.title = DateTimeUtil.GetDefaultDateTimeString((int)serieData.GetData(0), axisRange);
|
||||
tooltip.context.data.title = DateTimeUtil.GetDefaultDateTimeString((int)serieData.GetData(0), axisRange, !chart.useUtc);
|
||||
}
|
||||
}
|
||||
serie.handler.UpdateTooltipSerieParams(dataIndex, showCategory, category,
|
||||
|
||||
Reference in New Issue
Block a user