diff --git a/SunnyUI/Charts/UIBarChart.cs b/SunnyUI/Charts/UIBarChart.cs
index b8ed0f9c..7e0f352b 100644
--- a/SunnyUI/Charts/UIBarChart.cs
+++ b/SunnyUI/Charts/UIBarChart.cs
@@ -23,6 +23,7 @@
* 2022-03-08: V3.1.1 增加X轴文字倾斜
* 2022-05-27: V3.1.9 重写Y轴坐标显示
* 2022-07-29: V3.2.2 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces
+ * 2022-07-30: V3.2.2 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
******************************************************************************/
using System;
@@ -479,10 +480,7 @@ namespace Sunny.UI
if (Option.YAxis.AxisLabel.Show)
{
- if (Option.YAxis.AxisLabel.AutoFormat)
- Option.YAxis.AxisLabel.DecimalCount = YAxisDecimalCount;
-
- string label = YLabels[i].ToString("F" + Option.YAxis.AxisLabel.DecimalCount);
+ string label = YLabels[i].ToString(Option.YAxis.AxisLabel.DecimalPlaces >= 0 ? "F" + Option.YAxis.AxisLabel.DecimalPlaces : YScale.Format);
SizeF sf = g.MeasureString(label, TempFont);
g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, labels[i] - sf.Height / 2.0f);
}
diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs
index f746a426..cefdef0e 100644
--- a/SunnyUI/Charts/UILineChart.cs
+++ b/SunnyUI/Charts/UILineChart.cs
@@ -34,7 +34,10 @@
* 2022-04-19: V3.1.5 关闭Smooth绘制,数值差距大或者持续缩放会出错
* 2022-07-11: V3.2.1 修改两个点时可以不显示连接线
* 2022-07-26: V3.2.2 修复双Y轴数据点提示文字显示
- * 2022-07-30: V3.2.2 数据显示的小数位数重构调整至数据序列Series.XAxisDecimalPlaces,XAxisDateTimeFormat,YAxisDecimalPlaces
+ * 2022-07-30: V3.2.2 数据显示的小数位数重构调整至数据序列Series.XAxisDecimalPlaces,YAxisDecimalPlaces
+ * 2022-07-30: V3.2.2 数据显示的日期格式重构调整至数据序列Series.XAxisDateTimeFormat
+ * 2022-07-30: V3.2.2 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
+ * 2022-07-30: V3.2.2 坐标轴的日期格式重构调整至AxisLabel.DateTimeFormat
******************************************************************************/
using System;
@@ -306,17 +309,17 @@ namespace Sunny.UI
string label;
if (Option.XAxisType == UIAxisType.DateTime)
{
- if (Option.XAxis.AxisLabel.AutoFormat)
+ if (Option.XAxis.AxisLabel.DateTimeFormat.IsNullOrEmpty())
label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
else
label = new DateTimeInt64(XLabels[i]).ToString(Option.XAxis.AxisLabel.DateTimeFormat);
}
else
{
- if (Option.XAxis.AxisLabel.AutoFormat)
+ if (Option.XAxis.AxisLabel.DecimalPlaces < 0)
label = XLabels[i].ToString(XScale.Format);
else
- label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
+ label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalPlaces);
}
if (Option.XAxis.HaveCustomLabels && Option.XAxis.CustomLabels.GetLabel(i).IsValid())
@@ -369,7 +372,12 @@ namespace Sunny.UI
float y = labels[i];
if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom) continue;
- string label = YLabels[i].ToString(YScale.Format);
+ string label;
+ if (Option.YAxis.AxisLabel.DecimalPlaces < 0)
+ label = YLabels[i].ToString(YScale.Format);
+ else
+ label = YLabels[i].ToString("F" + Option.YAxis.AxisLabel.DecimalPlaces);
+
SizeF sf = g.MeasureString(label, TempFont);
widthMax = Math.Max(widthMax, sf.Width);
@@ -416,7 +424,12 @@ namespace Sunny.UI
if (Option.Y2Axis.AxisLabel.Show)
{
- string label = Y2Labels[i].ToString(Y2Scale.Format);
+ string label;
+ if (Option.Y2Axis.AxisLabel.DecimalPlaces < 0)
+ label = Y2Labels[i].ToString(Y2Scale.Format);
+ else
+ label = Y2Labels[i].ToString("F" + Option.Y2Axis.AxisLabel.DecimalPlaces);
+
SizeF sf = g.MeasureString(label, TempFont);
widthMax = Math.Max(widthMax, sf.Width);
g.DrawString(label, TempFont, ForeColor, Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length, y - sf.Height / 2.0f);
@@ -823,10 +836,21 @@ namespace Sunny.UI
sb.Append('\n');
sb.Append(Option.XAxis.Name + ": ");
- if (Option.XAxisType == UIAxisType.DateTime)
- sb.Append(new DateTimeInt64(point.X).ToString(point.Series.XAxisDateTimeFormat.IsValid() ? point.Series.XAxisDateTimeFormat : XScale.Format));
- else
- sb.Append(point.X.ToString(point.Series.XAxisDecimalPlaces >= 0 ? "F" + point.Series.XAxisDecimalPlaces : XScale.Format));
+ string customlabel = "";
+ if (Option.XAxis.HaveCustomLabels)
+ {
+ int ci = (int)point.X;
+ customlabel = Option.XAxis.CustomLabels.GetLabel(ci);
+ sb.Append(customlabel);
+ }
+
+ if (customlabel.IsNullOrEmpty())
+ {
+ if (Option.XAxisType == UIAxisType.DateTime)
+ sb.Append(new DateTimeInt64(point.X).ToString(point.Series.XAxisDateTimeFormat.IsValid() ? point.Series.XAxisDateTimeFormat : XScale.Format));
+ else
+ sb.Append(point.X.ToString(point.Series.XAxisDecimalPlaces >= 0 ? "F" + point.Series.XAxisDecimalPlaces : XScale.Format));
+ }
sb.Append('\n');
diff --git a/SunnyUI/Charts/UILineChartOption.cs b/SunnyUI/Charts/UILineChartOption.cs
index 6801e3fb..18f166db 100644
--- a/SunnyUI/Charts/UILineChartOption.cs
+++ b/SunnyUI/Charts/UILineChartOption.cs
@@ -331,6 +331,13 @@ namespace Sunny.UI
YAxisDecimalPlaces = yAxisDecimalPlaces;
}
+ public void ClearValueFormat()
+ {
+ _dateTimeFormat = "";
+ _xAxisDecimalPlaces = -1;
+ _yAxisDecimalPlaces = -1;
+ }
+
private int _xAxisDecimalPlaces = -1;
public int XAxisDecimalPlaces
{
diff --git a/SunnyUI/Charts/UIOption.cs b/SunnyUI/Charts/UIOption.cs
index dba999a2..85570eff 100644
--- a/SunnyUI/Charts/UIOption.cs
+++ b/SunnyUI/Charts/UIOption.cs
@@ -221,7 +221,7 @@ namespace Sunny.UI
public string GetLabel(int i)
{
- if (i < Labels.Count) return Labels[i];
+ if (i >= 0 && i < Labels.Count) return Labels[i];
else return string.Empty;
}
}
@@ -235,17 +235,44 @@ namespace Sunny.UI
public int Angle { get; set; } = 0;
- ///
- /// 小数位个数,Formatter不为空时以Formatter为准
- ///
- public int DecimalCount { get; set; } = 0;
+ private int decimalPlaces = -1;
///
- /// 日期格式化字符串,Formatter不为空时以Formatter为准
+ /// 小数位个数
///
- public string DateTimeFormat { get; set; } = "HH:mm";
+ public int DecimalPlaces
+ {
+ get => decimalPlaces;
+ set => decimalPlaces = Math.Max(0, value);
+ }
- public bool AutoFormat { get; set; } = true;
+ private string dateTimeFormat = "";
+
+ ///
+ /// 日期格式化字符串
+ ///
+ public string DateTimeFormat
+ {
+ get => dateTimeFormat;
+ set
+ {
+ try
+ {
+ DateTime.Now.ToString(value);
+ dateTimeFormat = value;
+ }
+ catch
+ {
+ dateTimeFormat = "";
+ }
+ }
+ }
+
+ public void ClearFormat()
+ {
+ dateTimeFormat = "";
+ decimalPlaces = -1;
+ }
}
public class UIAxisTick