2020-09-17 21:20:47 +08:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
2022-01-02 12:32:50 +08:00
|
|
|
|
* CopyRight (C) 2012-2022 ShenYongHua(沈永华).
|
2021-02-20 15:45:47 +08:00
|
|
|
|
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
2020-09-17 21:20:47 +08:00
|
|
|
|
*
|
|
|
|
|
* Blog: https://www.cnblogs.com/yhuse
|
|
|
|
|
* Gitee: https://gitee.com/yhuse/SunnyUI
|
|
|
|
|
* GitHub: https://github.com/yhuse/SunnyUI
|
|
|
|
|
*
|
|
|
|
|
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
|
|
|
|
* If you use this code, please keep this note.
|
|
|
|
|
* 如果您使用此代码,请保留此说明。
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* 文件名称: UIPieChartOption.cs
|
|
|
|
|
* 文件说明: 饼状图配置类
|
2022-01-05 21:57:47 +08:00
|
|
|
|
* 当前版本: V3.1
|
2020-09-17 21:20:47 +08:00
|
|
|
|
* 创建日期: 2020-06-06
|
|
|
|
|
*
|
|
|
|
|
* 2020-06-06: V2.2.5 增加文件说明
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-06-14 19:35:38 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-29 20:14:59 +08:00
|
|
|
|
using System.Drawing;
|
2020-06-14 19:35:38 +08:00
|
|
|
|
|
|
|
|
|
namespace Sunny.UI
|
|
|
|
|
{
|
2020-10-04 11:19:55 +08:00
|
|
|
|
public sealed class UIPieOption : UIOption, IDisposable
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
|
|
|
|
public List<UIPieSeries> Series = new List<UIPieSeries>();
|
|
|
|
|
|
2020-10-11 09:51:35 +08:00
|
|
|
|
public UIPieToolTip ToolTip { get; set; } = new UIPieToolTip();
|
2020-06-14 19:35:38 +08:00
|
|
|
|
|
|
|
|
|
public void AddSeries(UIPieSeries series)
|
|
|
|
|
{
|
|
|
|
|
Series.Clear();
|
|
|
|
|
Series.Add(series);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 析构函数
|
|
|
|
|
/// </summary>
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
foreach (var series in Series)
|
|
|
|
|
{
|
|
|
|
|
series?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Series.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int SeriesCount => Series.Count;
|
2021-07-21 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
public UIPieSeries this[string seriesName]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in Series)
|
|
|
|
|
{
|
|
|
|
|
if (item.Name == seriesName) return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-29 11:15:59 +08:00
|
|
|
|
|
|
|
|
|
private int decimalPlaces = 0;
|
|
|
|
|
public int DecimalPlaces
|
|
|
|
|
{
|
|
|
|
|
get => decimalPlaces;
|
|
|
|
|
set => decimalPlaces = Math.Max(0, value);
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public class UIDoughnutOption : UIOption, IDisposable
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public List<UIDoughnutSeries> Series = new List<UIDoughnutSeries>();
|
2020-06-14 19:35:38 +08:00
|
|
|
|
|
2020-10-11 09:51:35 +08:00
|
|
|
|
public UIPieToolTip ToolTip { get; set; } = new UIPieToolTip();
|
2020-06-14 19:35:38 +08:00
|
|
|
|
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public void AddSeries(UIDoughnutSeries series)
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
|
|
|
|
Series.Clear();
|
|
|
|
|
Series.Add(series);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 析构函数
|
|
|
|
|
/// </summary>
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
foreach (var series in Series)
|
|
|
|
|
{
|
|
|
|
|
series?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Series.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int SeriesCount => Series.Count;
|
2021-07-21 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
public UIDoughnutSeries this[string seriesName]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in Series)
|
|
|
|
|
{
|
|
|
|
|
if (item.Name == seriesName) return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-29 11:15:59 +08:00
|
|
|
|
|
|
|
|
|
private int decimalPlaces = 0;
|
|
|
|
|
public int DecimalPlaces
|
|
|
|
|
{
|
|
|
|
|
get => decimalPlaces;
|
|
|
|
|
set => decimalPlaces = Math.Max(0, value);
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-11 09:51:35 +08:00
|
|
|
|
public class UIPieToolTip : UIChartToolTip
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
2020-10-11 09:51:35 +08:00
|
|
|
|
public UIPieToolTip()
|
|
|
|
|
{
|
|
|
|
|
Formatter = "{{a}}" + '\n' + "{{b}} : {{c}} ({{d}}%)";
|
|
|
|
|
Visible = true;
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UIPieSeries : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public UISeriesType Type => UISeriesType.Pie;
|
|
|
|
|
|
|
|
|
|
public int Radius { get; set; } = 70;
|
|
|
|
|
|
|
|
|
|
public UICenter Center { get; set; } = new UICenter(50, 50);
|
|
|
|
|
|
|
|
|
|
public readonly List<UIPieSeriesData> Data = new List<UIPieSeriesData>();
|
|
|
|
|
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public UIPieSeriesLabel Label = new UIPieSeriesLabel();
|
|
|
|
|
|
2020-07-29 20:39:30 +08:00
|
|
|
|
public delegate Color OnDataColorChangeEventHandler(double data);
|
|
|
|
|
|
|
|
|
|
public event OnDataColorChangeEventHandler DataColorChange;
|
|
|
|
|
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void AddData(string name, double value)
|
|
|
|
|
{
|
2020-07-29 20:39:30 +08:00
|
|
|
|
if (DataColorChange != null)
|
|
|
|
|
{
|
2020-07-30 20:20:50 +08:00
|
|
|
|
Color color = DataColorChange.Invoke(value);
|
|
|
|
|
Data.Add(new UIPieSeriesData(name, value, color));
|
2020-07-29 20:39:30 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Data.Add(new UIPieSeriesData(name, value));
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-29 20:14:59 +08:00
|
|
|
|
public void AddData(string name, double value, Color color)
|
|
|
|
|
{
|
|
|
|
|
Data.Add(new UIPieSeriesData(name, value, color));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 析构函数
|
|
|
|
|
/// </summary>
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Data.Clear();
|
|
|
|
|
}
|
2021-07-21 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
public void Update(string name, double value)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in Data)
|
|
|
|
|
{
|
|
|
|
|
if (item.Name == name)
|
|
|
|
|
item.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RadiusInOut
|
|
|
|
|
{
|
|
|
|
|
public int Inner { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Outer { get; set; }
|
|
|
|
|
|
2020-07-29 20:14:59 +08:00
|
|
|
|
public RadiusInOut(int inner, int outer)
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
|
|
|
|
Inner = inner;
|
|
|
|
|
Outer = outer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public class UIDoughnutSeries : IDisposable
|
2020-06-14 19:35:38 +08:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public UISeriesType Type { get; set; }
|
|
|
|
|
|
2020-07-29 20:14:59 +08:00
|
|
|
|
public RadiusInOut Radius { get; set; } = new RadiusInOut(50, 70);
|
2020-06-14 19:35:38 +08:00
|
|
|
|
|
|
|
|
|
public UICenter Center { get; set; } = new UICenter(50, 50);
|
|
|
|
|
|
|
|
|
|
public readonly List<UIPieSeriesData> Data = new List<UIPieSeriesData>();
|
|
|
|
|
|
2020-06-26 15:13:36 +08:00
|
|
|
|
public UIPieSeriesLabel Label = new UIPieSeriesLabel();
|
|
|
|
|
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void AddData(string name, double value)
|
|
|
|
|
{
|
|
|
|
|
Data.Add(new UIPieSeriesData(name, value));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 21:25:21 +08:00
|
|
|
|
public void AddData(string name, double value, Color color)
|
|
|
|
|
{
|
|
|
|
|
Data.Add(new UIPieSeriesData(name, value, color));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 析构函数
|
|
|
|
|
/// </summary>
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Data.Clear();
|
|
|
|
|
}
|
2021-07-21 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
public void Update(string name, double value)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in Data)
|
|
|
|
|
{
|
|
|
|
|
if (item.Name == name)
|
|
|
|
|
item.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UIPieSeriesData
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public double Value { get; set; }
|
|
|
|
|
|
2020-07-29 20:14:59 +08:00
|
|
|
|
public Color Color { get; set; }
|
|
|
|
|
|
2020-07-30 20:20:50 +08:00
|
|
|
|
public bool StyleCustomMode { get; private set; }
|
2020-07-29 20:14:59 +08:00
|
|
|
|
|
2020-06-14 19:35:38 +08:00
|
|
|
|
public UIPieSeriesData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UIPieSeriesData(string name, double value)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Value = value;
|
2020-07-30 20:20:50 +08:00
|
|
|
|
StyleCustomMode = false;
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
2020-07-29 20:14:59 +08:00
|
|
|
|
|
|
|
|
|
public UIPieSeriesData(string name, double value, Color color)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Value = value;
|
|
|
|
|
Color = color;
|
|
|
|
|
StyleCustomMode = true;
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|
2020-06-26 15:13:36 +08:00
|
|
|
|
|
|
|
|
|
public class UIPieSeriesLabel
|
|
|
|
|
{
|
|
|
|
|
public bool Show { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
public UIPieSeriesLabelPosition Position { get; set; } = UIPieSeriesLabelPosition.Center;
|
|
|
|
|
|
|
|
|
|
public string Formatter { get; set; } = "{{b}}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum UIPieSeriesLabelPosition
|
|
|
|
|
{
|
|
|
|
|
Outside,
|
|
|
|
|
Inside,
|
|
|
|
|
Center
|
|
|
|
|
}
|
2020-06-14 19:35:38 +08:00
|
|
|
|
}
|