界面效果:
对外提供的属性设置
/// <summary> /// 背景色 /// </summary> public Color BackColor; /// <summary> /// 边框颜色 /// </summary> , , ); /// <summary> /// 线条颜色 /// </summary> , , ); /// <summary> /// 折线颜色 /// </summary> , , ); /// <summary> /// 是否显示控件边框 /// </summary> public bool rect_isvisable = false;
/// <summary> /// 边框线宽 /// </summary> ; /// <summary> /// 垂直线条间距 /// </summary> ; /// <summary> /// 水平线条间距 /// </summary> ; /// <summary> /// 点密度,越小越稀疏 /// </summary> private float point_density = 0.7f; #region public float Point_density { get { return point_density; } set { point_density = value; || value > ) { point_density = 0.7f; } } } public float Linewidth { get { return linewidth; } set { linewidth = value; ) { linewidth = ; } } } public int Vertical_spacing { get { return vertical_spacing; } set { ) { value = ; } vertical_spacing = value; } } public int Horizontal_spacing { get { return horizontal_spacing; } set { ) { value = ; } horizontal_spacing = value; } } #endregion
这些要保证是大于0,我使用属性了,这样比频繁的类型转换要好
绘制
protected override void OnPaint(PaintEventArgs pe) { this.drawtable(); this.drawpolygonal(); base.OnPaint(pe); } private void drawtable()//表格绘制 { if (this.rect_isvisable) { this.rectanglelinecolor = Color.Black; } else { this.rectanglelinecolor = this.BackColor; } Graphics g = this.CreateGraphics(); g.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle); )+this.vertical_spacing;i<this.Height;i+=this.vertical_spacing) { g.DrawLine(), this.ClientRectangle.X, i, this.Width, i); } )+this.Horizontal_spacing;i<this.Width;i+=this.Horizontal_spacing) { g.DrawLine(), i,this.ClientRectangle.Y,i, this.Height); } g.DrawRectangle(, , this.Width - this.linewidth, this.Height - this.linewidth); g.Dispose(); } /// <summary> /// 折线绘制 /// </summary> private void drawpolygonal() { Point ps=new Point(); Point pe; Graphics g = this.CreateGraphics(); ,j=; i>=;i--,j++) { float f = this.polygonalpoint[i]; int w = this.Width - this.Horizontal_spacing_per_pp*j; int h = this.Height - (int)(f * this.Height); pe = ps; ps = new Point(w, h); ) { g.DrawLine(p,pe, ps); } } }
链接:http://pan.baidu.com/s/1gdjod8J
添加到自己的项目里拖进去就可以了;和普通的控件一样使用
M$自己也有更好的linechart,不过插件肯定比较大的了