RaUI/Source/ryControls/ImageChart/RectanglePainter.cs
2020-11-28 15:03:57 +08:00

73 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace TChart.ImageChart
{
/// <summary>
/// 方块图
/// </summary>
/// <remarks>
/// 作者: Kingthy
/// 日期: 2007-09-11
/// MSN: Kingthy@gmail.com
/// 转载请注明原作者,当你有更新修改时如果方便的希望能发一份给我.谢谢
/// </remarks>
public class RectanglePainter : MovementPainterBase
{
/// <summary>
///
/// </summary>
/// <param name="image"></param>
public RectanglePainter(MovementImage image)
: base(image)
{
}
#region
/// <summary>
/// 画值
/// </summary>
/// <param name="graphics">画布</param>
/// <param name="xAxes">X轴数据</param>
public override void DrawValue(System.Drawing.Graphics graphics, XAxisItemList xAxes)
{
int tmpXSpaceWidth;
//tmpXSpaceWidth = Image.XSpaceWidth;
tmpXSpaceWidth = Image.Xspace;
//第一个X轴的起始点
Point p1 = new Point(tmpXSpaceWidth, Image.Height - Image.YSpaceWidth);
Point p2 = new Point(0, 0);
StringFormat format = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
int xSpaceOffset = Image.XSpaceWidth / 4;
for (int i = 0; i< xAxes.Count; i++)
{
XAxisItem item = xAxes[i];
p1.X += Image.XSpaceWidth;
//取得当前数据的结束点坐标
p2.X = p1.X;
p2.Y = this.GetYPosition(item.Value);
if (p2.Y < 0) p2.Y = 0;
//画距形
graphics.FillRectangle(new SolidBrush(item.DrawColor), new Rectangle(p2.X - xSpaceOffset, p2.Y, xSpaceOffset * 2, p1.Y - p2.Y));
//画值
if (item.ValueVisible)
{
//位置在 起始点的上方
graphics.DrawString(item.Value.ToString(), item.ValueFont, new SolidBrush(item.ValueColor), p2.X, p2.Y - this.Image.YSpaceWidth / 4, format);
}
}
}
#endregion
}
}