* UIBarChart:更改Y轴坐标刻度小数位自动计算
This commit is contained in:
parent
451e990674
commit
4c2dcd55ff
Binary file not shown.
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
@ -26,20 +26,20 @@ namespace Sunny.UI.Demo.Charts
|
||||
|
||||
var series = new UIBarSeries();
|
||||
series.Name = "Bar1";
|
||||
series.AddData(11);
|
||||
series.AddData(15);
|
||||
series.AddData(12);
|
||||
series.AddData(14);
|
||||
series.AddData(13);
|
||||
series.AddData(1.1);
|
||||
series.AddData(1.5);
|
||||
series.AddData(1.2);
|
||||
series.AddData(1.4);
|
||||
series.AddData(1.3);
|
||||
option.Series.Add(series);
|
||||
|
||||
series = new UIBarSeries();
|
||||
series.Name = "Bar2";
|
||||
series.AddData(-22);
|
||||
series.AddData(-28);
|
||||
series.AddData(-25);
|
||||
series.AddData(-23);
|
||||
series.AddData(-24);
|
||||
series.AddData(-2.2);
|
||||
series.AddData(-2.8);
|
||||
series.AddData(-2.5);
|
||||
series.AddData(-2.3);
|
||||
series.AddData(-2.4);
|
||||
option.Series.Add(series);
|
||||
|
||||
option.XAxis.Data.Add("Mon");
|
||||
|
@ -47,24 +47,24 @@ namespace Sunny.UI.Demo
|
||||
series.Name = "Bar1";
|
||||
series.ShowBarName = true;
|
||||
series.ShowValue = true;
|
||||
series.AddData("通道1", 11);
|
||||
series.AddData("通道2", 15);
|
||||
series.AddData("通道1", 1.1);
|
||||
series.AddData("通道2", 1.5);
|
||||
option.Series.Add(series);
|
||||
|
||||
series = new UIBarSeries();
|
||||
series.Name = "Bar2";
|
||||
series.ShowBarName = true;
|
||||
series.ShowValue = true;
|
||||
series.AddData("通道1", 22);
|
||||
series.AddData("通道2", 28);
|
||||
series.AddData("通道3", 25);
|
||||
series.AddData("通道1", 2.2);
|
||||
series.AddData("通道2", 2.8);
|
||||
series.AddData("通道3", 2.5);
|
||||
option.Series.Add(series);
|
||||
|
||||
series = new UIBarSeries();
|
||||
series.Name = "Bar3";
|
||||
series.ShowBarName = true;
|
||||
series.ShowValue = true;
|
||||
series.AddData("通道1", 7);
|
||||
series.AddData("通道1", 0.7);
|
||||
option.Series.Add(series);
|
||||
|
||||
option.XAxis.Data.Add("Mon");
|
||||
|
@ -53,7 +53,7 @@ namespace Sunny.UI
|
||||
/// <param name="degree_end">刻度结束值,须乘以间隔使用</param>
|
||||
/// <param name="degree_gap">刻度间隔</param>
|
||||
public void CalcDegreeScale(double start, double end, int expect_num,
|
||||
out int degree_start, out int degree_end, out double degree_gap)
|
||||
out int degree_start, out int degree_end, out double degree_gap, out int decimalCount)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
@ -101,6 +101,10 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
degree_end = end2;
|
||||
_exponent = Math.Abs(_exponent);
|
||||
if (fix_step.IsEven()) _exponent--;
|
||||
if (_exponent < 0) _exponent = 0;
|
||||
decimalCount = _exponent;
|
||||
}
|
||||
|
||||
protected override void CalcData()
|
||||
@ -142,11 +146,12 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
|
||||
out int start, out int end, out double interval);
|
||||
out int start, out int end, out double interval, out int decimalCount);
|
||||
|
||||
YAxisStart = start;
|
||||
YAxisEnd = end;
|
||||
YAxisInterval = interval;
|
||||
YAxisDecimalCount = decimalCount;
|
||||
|
||||
float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1);
|
||||
float x2 = x1 * 2;
|
||||
@ -250,6 +255,7 @@ namespace Sunny.UI
|
||||
protected int YAxisStart;
|
||||
protected int YAxisEnd;
|
||||
protected double YAxisInterval;
|
||||
protected int YAxisDecimalCount;
|
||||
protected readonly ConcurrentDictionary<int, List<BarInfo>> Bars = new ConcurrentDictionary<int, List<BarInfo>>();
|
||||
|
||||
[DefaultValue(-1), Browsable(false)]
|
||||
@ -501,6 +507,10 @@ namespace Sunny.UI
|
||||
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
||||
int idx = 0;
|
||||
float wmax = 0;
|
||||
|
||||
if (Option.YAxis.AxisLabel.AutoFormat)
|
||||
Option.YAxis.AxisLabel.DecimalCount = YAxisDecimalCount;
|
||||
|
||||
for (int i = YAxisStart; i <= YAxisEnd; i++)
|
||||
{
|
||||
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
|
||||
|
@ -74,11 +74,12 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
|
||||
out int start, out int end, out double interval);
|
||||
out int start, out int end, out double interval, out int decimalCount);
|
||||
|
||||
YAxisStart = start;
|
||||
YAxisEnd = end;
|
||||
YAxisInterval = interval;
|
||||
YAxisDecimalCount = decimalCount;
|
||||
float barX = DrawOrigin.X;
|
||||
|
||||
if (Option.AutoSizeBars)
|
||||
@ -460,6 +461,10 @@ namespace Sunny.UI
|
||||
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
||||
int idx = 0;
|
||||
float wmax = 0;
|
||||
|
||||
if (Option.YAxis.AxisLabel.AutoFormat)
|
||||
Option.YAxis.AxisLabel.DecimalCount = YAxisDecimalCount;
|
||||
|
||||
for (int i = YAxisStart; i <= YAxisEnd; i++)
|
||||
{
|
||||
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
|
||||
|
@ -177,6 +177,11 @@ namespace Sunny.UI
|
||||
return value.ToString("F2");
|
||||
}
|
||||
|
||||
public string GetAutoLabel(double value, int decimalCount)
|
||||
{
|
||||
return value.ToString("F" + decimalCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 小数位个数,Formatter不为空时以Formatter为准
|
||||
/// </summary>
|
||||
@ -186,6 +191,8 @@ namespace Sunny.UI
|
||||
/// 日期格式化字符串,Formatter不为空时以Formatter为准
|
||||
/// </summary>
|
||||
public string DateTimeFormat { get; set; } = "HH:mm";
|
||||
|
||||
public bool AutoFormat { get; set; } = true;
|
||||
}
|
||||
|
||||
public class UIAxisTick
|
||||
|
Loading…
x
Reference in New Issue
Block a user