* UILineChart: 数据显示的小数位数重构调整至数据序列Series.XAxisDecimalPlaces,YAxisDecimalPlaces

* UILineChart:  数据显示的日期格式重构调整至数据序列Series.XAxisDateTimeFormat
* UILineChart:  坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
* UILineChart:  坐标轴的日期格式重构调整至AxisLabel.DateTimeFormat
* UIBarChart: 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces
* UIBarChart: 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
This commit is contained in:
Sunny 2022-07-30 11:03:49 +08:00
parent 0fd7299962
commit db0eb984cb
4 changed files with 78 additions and 22 deletions

View File

@ -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);
}

View File

@ -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.XAxisDecimalPlacesXAxisDateTimeFormatYAxisDecimalPlaces
* 2022-07-30: V3.2.2 Series.XAxisDecimalPlacesYAxisDecimalPlaces
* 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');

View File

@ -331,6 +331,13 @@ namespace Sunny.UI
YAxisDecimalPlaces = yAxisDecimalPlaces;
}
public void ClearValueFormat()
{
_dateTimeFormat = "";
_xAxisDecimalPlaces = -1;
_yAxisDecimalPlaces = -1;
}
private int _xAxisDecimalPlaces = -1;
public int XAxisDecimalPlaces
{

View File

@ -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;
/// <summary>
/// 小数位个数Formatter不为空时以Formatter为准
/// </summary>
public int DecimalCount { get; set; } = 0;
private int decimalPlaces = -1;
/// <summary>
/// 日期格式化字符串Formatter不为空时以Formatter为准
/// 小数位个数
/// </summary>
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 = "";
/// <summary>
/// 日期格式化字符串
/// </summary>
public string DateTimeFormat
{
get => dateTimeFormat;
set
{
try
{
DateTime.Now.ToString(value);
dateTimeFormat = value;
}
catch
{
dateTimeFormat = "";
}
}
}
public void ClearFormat()
{
dateTimeFormat = "";
decimalPlaces = -1;
}
}
public class UIAxisTick