SunnyUI/SunnyUI/Charts/UIPieChartOption.cs

287 lines
7.1 KiB
C#
Raw Normal View History

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 QQ17612584 EMailSunnyUI@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;
using System.Collections.Generic;
using System.Drawing;
namespace Sunny.UI
{
public sealed class UIPieOption : UIOption, IDisposable
{
public List<UIPieSeries> Series = new List<UIPieSeries>();
public UIPieToolTip ToolTip { get; set; } = new UIPieToolTip();
public void AddSeries(UIPieSeries series)
{
Series.Clear();
Series.Add(series);
}
2022-06-27 17:06:11 +08:00
/// <summary>
/// 析构函数
/// </summary>
public void Dispose()
{
foreach (var series in Series)
{
series?.Dispose();
}
Series.Clear();
}
public int SeriesCount => Series.Count;
public UIPieSeries this[string seriesName]
{
get
{
foreach (var item in Series)
{
if (item.Name == seriesName) return item;
}
return null;
}
}
private int decimalPlaces = 0;
public int DecimalPlaces
{
get => decimalPlaces;
set => decimalPlaces = Math.Max(0, value);
}
}
public class UIDoughnutOption : UIOption, IDisposable
{
public List<UIDoughnutSeries> Series = new List<UIDoughnutSeries>();
public UIPieToolTip ToolTip { get; set; } = new UIPieToolTip();
public void AddSeries(UIDoughnutSeries series)
{
Series.Clear();
Series.Add(series);
}
2022-06-27 17:06:11 +08:00
/// <summary>
/// 析构函数
/// </summary>
public void Dispose()
{
foreach (var series in Series)
{
series?.Dispose();
}
Series.Clear();
}
public int SeriesCount => Series.Count;
public UIDoughnutSeries this[string seriesName]
{
get
{
foreach (var item in Series)
{
if (item.Name == seriesName) return item;
}
return null;
}
}
private int decimalPlaces = 0;
public int DecimalPlaces
{
get => decimalPlaces;
set => decimalPlaces = Math.Max(0, value);
}
}
public class UIPieToolTip : UIChartToolTip
{
public UIPieToolTip()
{
Formatter = "{{a}}" + '\n' + "{{b}} : {{c}} ({{d}}%)";
Visible = true;
}
}
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>();
public UIPieSeriesLabel Label = new UIPieSeriesLabel();
public delegate Color OnDataColorChangeEventHandler(double data);
public event OnDataColorChangeEventHandler DataColorChange;
public void AddData(string name, double value)
{
if (DataColorChange != null)
{
2020-07-30 20:20:50 +08:00
Color color = DataColorChange.Invoke(value);
Data.Add(new UIPieSeriesData(name, value, color));
}
else
{
Data.Add(new UIPieSeriesData(name, value));
}
}
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>
public void Dispose()
{
Data.Clear();
}
public void Update(string name, double value)
{
foreach (var item in Data)
{
if (item.Name == name)
item.Value = value;
}
}
}
public class RadiusInOut
{
public int Inner { get; set; }
public int Outer { get; set; }
public RadiusInOut(int inner, int outer)
{
Inner = inner;
Outer = outer;
}
}
public class UIDoughnutSeries : IDisposable
{
public string Name { get; set; }
public UISeriesType Type { get; set; }
public RadiusInOut Radius { get; set; } = new RadiusInOut(50, 70);
public UICenter Center { get; set; } = new UICenter(50, 50);
public readonly List<UIPieSeriesData> Data = new List<UIPieSeriesData>();
public UIPieSeriesLabel Label = new UIPieSeriesLabel();
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>
public void Dispose()
{
Data.Clear();
}
public void Update(string name, double value)
{
foreach (var item in Data)
{
if (item.Name == name)
item.Value = value;
}
}
}
public class UIPieSeriesData
{
public string Name { get; set; }
public double Value { get; set; }
public Color Color { get; set; }
2020-07-30 20:20:50 +08:00
public bool StyleCustomMode { get; private set; }
public UIPieSeriesData()
{
}
public UIPieSeriesData(string name, double value)
{
Name = name;
Value = value;
2020-07-30 20:20:50 +08:00
StyleCustomMode = false;
}
public UIPieSeriesData(string name, double value, Color color)
{
Name = name;
Value = value;
Color = color;
StyleCustomMode = true;
}
}
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
}
}