Commit 8f103baa HZH

增加内置颜色

1 个父辈 f598bc9d
...@@ -29,17 +29,13 @@ namespace HZH_Controls.Controls ...@@ -29,17 +29,13 @@ namespace HZH_Controls.Controls
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BarChartItem"/> class. /// Initializes a new instance of the <see cref="BarChartItem"/> class.
/// </summary> /// </summary>
public BarChartItem() { }
/// <summary>
/// Initializes a new instance of the <see cref="BarChartItem"/> class.
/// </summary>
/// <param name="_barBackColor">Color of the bar back.</param> /// <param name="_barBackColor">Color of the bar back.</param>
/// <param name="_itemName">Name of the item.</param> /// <param name="_itemName">Name of the item.</param>
/// <param name="_barPercentWidth">柱状图占平均宽度的百分比,默认0.8,即80%.</param> /// <param name="_barPercentWidth">柱状图占平均宽度的百分比,默认0.8,即80%.</param>
public BarChartItem( public BarChartItem(
Color _barBackColor,
string _itemName = "", string _itemName = "",
float _barPercentWidth = 0.8f) Color? _barBackColor = null,
float _barPercentWidth = 0.9f)
{ {
barBackColor = _barBackColor; barBackColor = _barBackColor;
itemName = _itemName; itemName = _itemName;
...@@ -48,13 +44,13 @@ namespace HZH_Controls.Controls ...@@ -48,13 +44,13 @@ namespace HZH_Controls.Controls
/// <summary> /// <summary>
/// The bar back color /// The bar back color
/// </summary> /// </summary>
private Color barBackColor = Color.FromArgb(255, 77, 59); private Color? barBackColor ;
/// <summary> /// <summary>
/// Gets or sets the color of the bar back. /// Gets or sets the color of the bar back.
/// </summary> /// </summary>
/// <value>The color of the bar back.</value> /// <value>The color of the bar back.</value>
public Color BarBackColor public Color? BarBackColor
{ {
get { return barBackColor; } get { return barBackColor; }
set { barBackColor = value; } set { barBackColor = value; }
...@@ -63,10 +59,10 @@ namespace HZH_Controls.Controls ...@@ -63,10 +59,10 @@ namespace HZH_Controls.Controls
/// <summary> /// <summary>
/// The bar percent width /// The bar percent width
/// </summary> /// </summary>
private float barPercentWidth = 0.8f; private float barPercentWidth = 0.9f;
/// <summary> /// <summary>
/// 获取或设置柱状图占平均宽度的百分比,默认0.8,即80% /// 获取或设置柱状图占平均宽度的百分比,默认0.9,即90%
/// </summary> /// </summary>
/// <value>The width of the bar percent.</value> /// <value>The width of the bar percent.</value>
public float BarPercentWidth public float BarPercentWidth
......
...@@ -641,7 +641,7 @@ namespace HZH_Controls.Controls ...@@ -641,7 +641,7 @@ namespace HZH_Controls.Controls
for (int j = i * intItemNameComCount; j < barChartItems.Length && j < (i + 1) * intItemNameComCount; j++) for (int j = i * intItemNameComCount; j < barChartItems.Length && j < (i + 1) * intItemNameComCount; j++)
{ {
Rectangle rectColor = new Rectangle(intLeft + (j % intItemNameComCount) * intItemNameWidth, intTop, 20, intItemNameHeight); Rectangle rectColor = new Rectangle(intLeft + (j % intItemNameComCount) * intItemNameWidth, intTop, 20, intItemNameHeight);
g.FillRectangle(new SolidBrush(barChartItems[j].BarBackColor), rectColor); g.FillRectangle(new SolidBrush(barChartItems[j].BarBackColor??ControlHelper.Colors[j]), rectColor);
g.DrawString(barChartItems[j].ItemName, Font, new SolidBrush(ForeColor), new Point(rectColor.Right + 2, rectColor.Top)); g.DrawString(barChartItems[j].ItemName, Font, new SolidBrush(ForeColor), new Point(rectColor.Right + 2, rectColor.Top));
} }
} }
...@@ -721,7 +721,7 @@ namespace HZH_Controls.Controls ...@@ -721,7 +721,7 @@ namespace HZH_Controls.Controls
RectangleF rect = new RectangleF(_fltLeft + _fltSplitWidth * j + (1F - barChartItems[j].BarPercentWidth) * _fltSplitWidth / 2f, fltValueY, RectangleF rect = new RectangleF(_fltLeft + _fltSplitWidth * j + (1F - barChartItems[j].BarPercentWidth) * _fltSplitWidth / 2f, fltValueY,
_fltSplitWidth * barChartItems[j].BarPercentWidth, (float)(height - intBottomY) - fltValueY); _fltSplitWidth * barChartItems[j].BarPercentWidth, (float)(height - intBottomY) - fltValueY);
Color color = barChartItems[j].BarBackColor; Color color = barChartItems[j].BarBackColor ?? ControlHelper.Colors[j];
//画柱状 //画柱状
if (useGradient) if (useGradient)
......
...@@ -18,6 +18,7 @@ using System.Collections.Generic; ...@@ -18,6 +18,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
...@@ -804,5 +805,68 @@ namespace HZH_Controls ...@@ -804,5 +805,68 @@ namespace HZH_Controls
roundedRect.CloseFigure(); roundedRect.CloseFigure();
return roundedRect; return roundedRect;
} }
/// <summary>
/// Gets the colors.
/// </summary>
/// <value>The colors.</value>
public static Color[] Colors { get; private set; }
static ControlHelper()
{
List<Color> list = new List<Color>();
list.Add(Color.FromArgb(243, 67, 54));
list.Add(Color.FromArgb(156, 39, 176));
list.Add(Color.FromArgb(233, 30, 99));
list.Add(Color.FromArgb(103, 58, 183));
list.Add(Color.FromArgb(63, 81, 181));
list.Add(Color.FromArgb(33, 150, 243));
list.Add(Color.FromArgb(0, 188, 211));
list.Add(Color.FromArgb(3, 169, 244));
list.Add(Color.FromArgb(0, 150, 136));
list.Add(Color.FromArgb(139, 195, 74));
list.Add(Color.FromArgb(76, 175, 80));
list.Add(Color.FromArgb(204, 219, 57));
list.Add(Color.FromArgb(254, 234, 59));
list.Add(Color.FromArgb(254, 192, 7));
list.Add(Color.FromArgb(254, 152, 0));
list.Add(Color.FromArgb(255, 87, 34));
list.Add(Color.FromArgb(121, 85, 72));
list.Add(Color.FromArgb(158, 158, 158));
list.Add(Color.FromArgb(96, 125, 139));
list.Add(Color.FromArgb(252, 117, 85));
list.Add(Color.FromArgb(172, 113, 191));
list.Add(Color.FromArgb(115, 131, 253));
list.Add(Color.FromArgb(78, 206, 255));
list.Add(Color.FromArgb(121, 195, 82));
list.Add(Color.FromArgb(255, 163, 28));
list.Add(Color.FromArgb(255, 185, 15));
list.Add(Color.FromArgb(255, 181, 197));
list.Add(Color.FromArgb(255, 110, 180));
list.Add(Color.FromArgb(255, 69, 0));
list.Add(Color.FromArgb(255, 48, 48));
list.Add(Color.FromArgb(154, 205, 50));
list.Add(Color.FromArgb(155, 205, 155));
list.Add(Color.FromArgb(154, 50, 205));
list.Add(Color.FromArgb(131, 111, 255));
list.Add(Color.FromArgb(124, 205, 124));
list.Add(Color.FromArgb(0, 206, 209));
list.Add(Color.FromArgb(0, 178, 238));
list.Add(Color.FromArgb(56, 142, 142));
Type typeFromHandle = typeof(Color);
PropertyInfo[] properties = typeFromHandle.GetProperties();
PropertyInfo[] array = properties;
for (int i = 0; i < array.Length; i++)
{
PropertyInfo propertyInfo = array[i];
if (propertyInfo.PropertyType == typeof(Color) && (propertyInfo.Name.StartsWith("Dark") || propertyInfo.Name.StartsWith("Medium")))
{
object value = propertyInfo.GetValue(null, null);
list.Add((Color)value);
}
}
Colors = list.ToArray();
}
} }
} }
...@@ -34,7 +34,7 @@ namespace Test ...@@ -34,7 +34,7 @@ namespace Test
{ {
ds[i] = new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) }; ds[i] = new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) };
} }
this.ucBarChart6.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem(Color.Red, "语文"), new HZH_Controls.Controls.BarChartItem(Color.Blue, "英语"), new HZH_Controls.Controls.BarChartItem(Color.Orange, "数学") }; this.ucBarChart6.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem("语文"), new HZH_Controls.Controls.BarChartItem("英语"), new HZH_Controls.Controls.BarChartItem("数学") };
this.ucBarChart6.SetDataSource(ds, new string[] { "张三", "李四", "王五", "赵六", "田七" }); this.ucBarChart6.SetDataSource(ds, new string[] { "张三", "李四", "王五", "赵六", "田七" });
this.ucBarChart6.AddAuxiliaryLine(60, Color.Black); this.ucBarChart6.AddAuxiliaryLine(60, Color.Black);
...@@ -44,12 +44,12 @@ namespace Test ...@@ -44,12 +44,12 @@ namespace Test
ds2.Add(new double[] { random.Next(800, 2000), random.Next(100, 200) }); ds2.Add(new double[] { random.Next(800, 2000), random.Next(100, 200) });
} }
var titles = new List<string>(); var titles = new List<string>();
double dblSum = ds2.Sum(p=>p[0]); double dblSum = ds2.Sum(p => p[0]);
for (int i = 0; i < ds2.Count; i++) for (int i = 0; i < ds2.Count; i++)
{ {
titles.Add("员工" + (i + 1) + "\n" + (ds2[i][0] / dblSum).ToString("0.0%")); titles.Add("员工" + (i + 1) + "\n" + (ds2[i][0] / dblSum).ToString("0.0%"));
} }
this.ucBarChart7.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem(Color.Green, "合格"), new HZH_Controls.Controls.BarChartItem(Color.Red, "次品") }; this.ucBarChart7.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem("合格"), new HZH_Controls.Controls.BarChartItem("次品") };
this.ucBarChart7.SetDataSource(ds2.ToArray(), titles.ToArray()); this.ucBarChart7.SetDataSource(ds2.ToArray(), titles.ToArray());
this.ucBarChart7.AddAuxiliaryLine(1000, Color.Black, "标准线"); this.ucBarChart7.AddAuxiliaryLine(1000, Color.Black, "标准线");
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!