* UILineChart: 数据显示的小数位数重构调整至数据序列Series.XAxisDecimalPlaces,YAxisDecimalPlaces
* UILineChart: 数据显示的日期格式重构调整至数据序列Series.XAxisDateTimeFormat * UILineChart: 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces * UILineChart: 坐标轴的日期格式重构调整至AxisLabel.DateTimeFormat * UIBarChart: 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces * UIBarChart: 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
This commit is contained in:
parent
0fd7299962
commit
db0eb984cb
@ -23,6 +23,7 @@
|
|||||||
* 2022-03-08: V3.1.1 增加X轴文字倾斜
|
* 2022-03-08: V3.1.1 增加X轴文字倾斜
|
||||||
* 2022-05-27: V3.1.9 重写Y轴坐标显示
|
* 2022-05-27: V3.1.9 重写Y轴坐标显示
|
||||||
* 2022-07-29: V3.2.2 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces
|
* 2022-07-29: V3.2.2 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces
|
||||||
|
* 2022-07-30: V3.2.2 坐标轴的小数位数重构调整至AxisLabel.DecimalPlaces
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -479,10 +480,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (Option.YAxis.AxisLabel.Show)
|
if (Option.YAxis.AxisLabel.Show)
|
||||||
{
|
{
|
||||||
if (Option.YAxis.AxisLabel.AutoFormat)
|
string label = YLabels[i].ToString(Option.YAxis.AxisLabel.DecimalPlaces >= 0 ? "F" + Option.YAxis.AxisLabel.DecimalPlaces : YScale.Format);
|
||||||
Option.YAxis.AxisLabel.DecimalCount = YAxisDecimalCount;
|
|
||||||
|
|
||||||
string label = YLabels[i].ToString("F" + Option.YAxis.AxisLabel.DecimalCount);
|
|
||||||
SizeF sf = g.MeasureString(label, TempFont);
|
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);
|
g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, labels[i] - sf.Height / 2.0f);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,10 @@
|
|||||||
* 2022-04-19: V3.1.5 关闭Smooth绘制,数值差距大或者持续缩放会出错
|
* 2022-04-19: V3.1.5 关闭Smooth绘制,数值差距大或者持续缩放会出错
|
||||||
* 2022-07-11: V3.2.1 修改两个点时可以不显示连接线
|
* 2022-07-11: V3.2.1 修改两个点时可以不显示连接线
|
||||||
* 2022-07-26: V3.2.2 修复双Y轴数据点提示文字显示
|
* 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;
|
using System;
|
||||||
@ -306,17 +309,17 @@ namespace Sunny.UI
|
|||||||
string label;
|
string label;
|
||||||
if (Option.XAxisType == UIAxisType.DateTime)
|
if (Option.XAxisType == UIAxisType.DateTime)
|
||||||
{
|
{
|
||||||
if (Option.XAxis.AxisLabel.AutoFormat)
|
if (Option.XAxis.AxisLabel.DateTimeFormat.IsNullOrEmpty())
|
||||||
label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
|
label = new DateTimeInt64(XLabels[i]).ToString(XScale.Format);
|
||||||
else
|
else
|
||||||
label = new DateTimeInt64(XLabels[i]).ToString(Option.XAxis.AxisLabel.DateTimeFormat);
|
label = new DateTimeInt64(XLabels[i]).ToString(Option.XAxis.AxisLabel.DateTimeFormat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Option.XAxis.AxisLabel.AutoFormat)
|
if (Option.XAxis.AxisLabel.DecimalPlaces < 0)
|
||||||
label = XLabels[i].ToString(XScale.Format);
|
label = XLabels[i].ToString(XScale.Format);
|
||||||
else
|
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())
|
if (Option.XAxis.HaveCustomLabels && Option.XAxis.CustomLabels.GetLabel(i).IsValid())
|
||||||
@ -369,7 +372,12 @@ namespace Sunny.UI
|
|||||||
float y = labels[i];
|
float y = labels[i];
|
||||||
if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom) continue;
|
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);
|
SizeF sf = g.MeasureString(label, TempFont);
|
||||||
widthMax = Math.Max(widthMax, sf.Width);
|
widthMax = Math.Max(widthMax, sf.Width);
|
||||||
|
|
||||||
@ -416,7 +424,12 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (Option.Y2Axis.AxisLabel.Show)
|
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);
|
SizeF sf = g.MeasureString(label, TempFont);
|
||||||
widthMax = Math.Max(widthMax, sf.Width);
|
widthMax = Math.Max(widthMax, sf.Width);
|
||||||
g.DrawString(label, TempFont, ForeColor, Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length, y - sf.Height / 2.0f);
|
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('\n');
|
||||||
sb.Append(Option.XAxis.Name + ": ");
|
sb.Append(Option.XAxis.Name + ": ");
|
||||||
|
|
||||||
if (Option.XAxisType == UIAxisType.DateTime)
|
string customlabel = "";
|
||||||
sb.Append(new DateTimeInt64(point.X).ToString(point.Series.XAxisDateTimeFormat.IsValid() ? point.Series.XAxisDateTimeFormat : XScale.Format));
|
if (Option.XAxis.HaveCustomLabels)
|
||||||
else
|
{
|
||||||
sb.Append(point.X.ToString(point.Series.XAxisDecimalPlaces >= 0 ? "F" + point.Series.XAxisDecimalPlaces : XScale.Format));
|
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');
|
sb.Append('\n');
|
||||||
|
|
||||||
|
@ -331,6 +331,13 @@ namespace Sunny.UI
|
|||||||
YAxisDecimalPlaces = yAxisDecimalPlaces;
|
YAxisDecimalPlaces = yAxisDecimalPlaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearValueFormat()
|
||||||
|
{
|
||||||
|
_dateTimeFormat = "";
|
||||||
|
_xAxisDecimalPlaces = -1;
|
||||||
|
_yAxisDecimalPlaces = -1;
|
||||||
|
}
|
||||||
|
|
||||||
private int _xAxisDecimalPlaces = -1;
|
private int _xAxisDecimalPlaces = -1;
|
||||||
public int XAxisDecimalPlaces
|
public int XAxisDecimalPlaces
|
||||||
{
|
{
|
||||||
|
@ -221,7 +221,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public string GetLabel(int i)
|
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;
|
else return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,17 +235,44 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public int Angle { get; set; } = 0;
|
public int Angle { get; set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
private int decimalPlaces = -1;
|
||||||
/// 小数位个数,Formatter不为空时以Formatter为准
|
|
||||||
/// </summary>
|
|
||||||
public int DecimalCount { get; set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日期格式化字符串,Formatter不为空时以Formatter为准
|
/// 小数位个数
|
||||||
/// </summary>
|
/// </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
|
public class UIAxisTick
|
||||||
|
Loading…
x
Reference in New Issue
Block a user