分享一个winForm下的Chart控件

转载 2011年01月23日 16:23:00

http://www.cnblogs.com/zzy0471/archive/2011/01/23/1942316.html

 

本来可以用MsChart的,但是客户有两个需求(绘制指定值的分割线;以对数方式显示数据)不好满足,只好自己写了一个,代码很乱,不过可以给有类似需求的同学以参考,顺便也请大家帮忙看看bug,因为要在项目中用,时间匆忙,也未做仔细测试,请感兴趣的园友帮忙看看,给点意见,谢谢。

  本控件和Ms控件相比,功能比较简单,实用为上,没有那么多属性可以设置,以下是为满足特定需求而添加的属性

  • 添加了一个用于插入分割线的属性
  • 添加了一种以对数形式显示数据的图表

  暂时这样,用到其他功能时再加,:-D。以下是使用示例:

     示例1:折线图

     示例2:区域图

     示例3:点图

     示例4:饼图

     示例5:对数折线图

  示例1:折线图

代码
private void InitChart()
{
this.chart1.BackColor = Color.Black;

this.chart1.ChartArea.ChartType = Enums.ChartType.Line;
this.chart1.ChartArea.Data = this.dsTest1.Tables[0];
this.chart1.ChartArea.XValueMember = "F_X";

StringInfo chartTitle
= new StringInfo();
chartTitle.Value
= "LineChart";
chartTitle.Color
= Color.DarkBlue;
chartTitle.Size
= 15;
this.chart1.ChartArea.ChartTitle = chartTitle;

this.chart1.ChartArea.AxisLineColor = Color.DarkSeaGreen;
this.chart1.ChartArea.AxisLineWidth = 2;

PartingLine line
= new PartingLine();
line.YValue
= 50;
line.LineColor
= Color.GreenYellow;
this.chart1.ChartArea.PartingLines.Add(line);

StringInfo axisXLable
= new StringInfo();
axisXLable.Size
= 12;
axisXLable.Color
= Color.Silver;
axisXLable.Value
= "时间";
this.chart1.ChartArea.AxisX.Lable = axisXLable;

this.chart1.ChartArea.AxisX.Interval = 1;
this.chart1.ChartArea.AxisX.IntervalType = Enums.InervalType.Hours;
this.chart1.ChartArea.AxisX.TimeFormat = "MM-dd HH:mm";
this.chart1.ChartArea.AxisX.Grid.LineColor = Color.RosyBrown;
this.chart1.ChartArea.AxisX.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisX.ShowGrid = true;

StringInfo axisYLable
= new StringInfo();
axisYLable.Size
= 12;
axisYLable.Color
= Color.Silver;
axisYLable.Value
= "数据";
this.chart1.ChartArea.AxisY1.Lable = axisYLable;

this.chart1.ChartArea.AxisY1.Interval = 10;
this.chart1.ChartArea.AxisY1.IntervalType = Enums.InervalType.Number;
this.chart1.ChartArea.AxisY1.Grid.LineColor = Color.SaddleBrown;
this.chart1.ChartArea.AxisY1.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisY1.ShowGrid = true;

Series series1
= new Series();
series1.Name
= "SeriesOne";
series1.Color
= Color.Red;
series1.Width
= 1;
series1.YValueMember
= "F_Y1";
this.chart1.ChartArea.Series.Add(series1);

Series series2
= new Series();
series2.Name
= "SeriesTwo";
series2.Color
= Color.RoyalBlue;
series2.Width
= 1;
series2.YValueMember
= "F_Y2";
this.chart1.ChartArea.Series.Add(series2);

Series series3
= new Series();
series3.Name
= "SeriesThree";
series3.Color
= Color.SeaShell;
series3.Width
= 1;
series3.YValueMember
= "F_Y3";
this.chart1.ChartArea.Series.Add(series3);
}

 

示例2:区域图

代码
private void InitChart()
{
this.chart1.BackColor = Color.Black;

this.chart1.ChartArea.ChartType = Enums.ChartType.Area;
this.chart1.ChartArea.Data = this.dsTest1.Tables[0];
this.chart1.ChartArea.XValueMember = "F_Y1";

StringInfo chartTitle
= new StringInfo();
chartTitle.Value
= "AreaChart";
chartTitle.Color
= Color.DarkBlue;
chartTitle.Size
= 15;
this.chart1.ChartArea.ChartTitle = chartTitle;

this.chart1.ChartArea.AxisLineColor = Color.DarkSeaGreen;
this.chart1.ChartArea.AxisLineWidth = 2;

StringInfo axisXLable
= new StringInfo();
axisXLable.Size
= 12;
axisXLable.Color
= Color.Silver;
axisXLable.Value
= "时间";
this.chart1.ChartArea.AxisX.Lable = axisXLable;

this.chart1.ChartArea.AxisX.Interval = 0.5;
this.chart1.ChartArea.AxisX.IntervalType = Enums.InervalType.Number;
// this.chart1.ChartArea.AxisX.TimeFormat = "yyyy-MM";
this.chart1.ChartArea.AxisX.Grid.LineColor = Color.RosyBrown;
this.chart1.ChartArea.AxisX.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisX.ShowGrid = true;

StringInfo axisYLable
= new StringInfo();
axisYLable.Size
= 12;
axisYLable.Color
= Color.Silver;
axisYLable.Value
= "数据";
this.chart1.ChartArea.AxisY1.Lable = axisYLable;

this.chart1.ChartArea.AxisY1.Interval = 10;
this.chart1.ChartArea.AxisY1.IntervalType = Enums.InervalType.Number;
this.chart1.ChartArea.AxisY1.Grid.LineColor = Color.SaddleBrown;
this.chart1.ChartArea.AxisY1.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisY1.ShowGrid = true;

Series series1
= new Series();
series1.Name
= "SeriesOne";
//series1.Color = Color.Red;
series1.Width = 1;
series1.YValueMember
= "F_Y1";
this.chart1.ChartArea.Series.Add(series1);

Series series2
= new Series();
series2.Name
= "SeriesTwo";
//series2.Color = Color.RoyalBlue;
series2.Width = 1;
series2.YValueMember
= "F_Y2";
this.chart1.ChartArea.Series.Add(series2);

Series series3
= new Series();
series3.Name
= "SeriesThree";
//series3.Color = Color.SeaShell;
series3.Width = 1;
series3.YValueMember
= "F_Y3";
this.chart1.ChartArea.Series.Add(series3);
}

 

示例3:点图

代码
private void InitChart()
{
this.chart1.BackColor = Color.Black;

this.chart1.ChartArea.ChartType = Enums.ChartType.Dot;
this.chart1.ChartArea.Data = this.dsTest1.Tables[0];
this.chart1.ChartArea.XValueMember = "F_X";

StringInfo chartTitle
= new StringInfo();
chartTitle.Value
= "LineChart";
chartTitle.Color
= Color.DarkBlue;
chartTitle.Size
= 15;
this.chart1.ChartArea.ChartTitle = chartTitle;

this.chart1.ChartArea.AxisLineColor = Color.DarkSeaGreen;
this.chart1.ChartArea.AxisLineWidth = 2;

PartingLine line
= new PartingLine();
line.YValue
= 50;
line.LineColor
= Color.GreenYellow;
this.chart1.ChartArea.PartingLines.Add(line);

StringInfo axisXLable
= new StringInfo();
axisXLable.Size
= 12;
axisXLable.Color
= Color.Silver;
axisXLable.Value
= "时间";
this.chart1.ChartArea.AxisX.Lable = axisXLable;

this.chart1.ChartArea.AxisX.Interval = 1;
this.chart1.ChartArea.AxisX.IntervalType = Enums.InervalType.Hours;
this.chart1.ChartArea.AxisX.TimeFormat = "MM-dd HH:mm";
this.chart1.ChartArea.AxisX.Grid.LineColor = Color.RosyBrown;
this.chart1.ChartArea.AxisX.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisX.ShowGrid = true;

StringInfo axisYLable
= new StringInfo();
axisYLable.Size
= 12;
axisYLable.Color
= Color.Silver;
axisYLable.Value
= "数据";
this.chart1.ChartArea.AxisY1.Lable = axisYLable;

this.chart1.ChartArea.AxisY1.Interval = 10;
this.chart1.ChartArea.AxisY1.IntervalType = Enums.InervalType.Number;
this.chart1.ChartArea.AxisY1.Grid.LineColor = Color.SaddleBrown;
this.chart1.ChartArea.AxisY1.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisY1.ShowGrid = true;

Series series1
= new Series();
series1.Name
= "SeriesOne";
series1.Color
= Color.Red;
series1.Width
= 4;//最小设置为2,再小了看不见了
series1.YValueMember = "F_Y1";
this.chart1.ChartArea.Series.Add(series1);
}

 

示例4:饼图

代码
private void InitChart()
{
this.chart1.ChartArea.Data = _testDt;
this.chart1.ChartArea.ChartType = Ultra.OpenChart.Entities.Enums.ChartType.Pie;
StringInfo title
= new StringInfo();
title.Value
= "PieChart";
title.Size
= 14;
title.Color
= Color.Salmon;
this.chart1.ChartArea.ChartTitle = title;
chart1.ChartArea.XValueMember
= "Country";

Series series
= new Series();
series.YValueMember
= "Number";
this.chart1.ChartArea.Series.Add(series);
}

 

示例5:对数折线图

代码
private void InitChart()
{
this.chart1.BackColor = Color.Black;

this.chart1.ChartArea.ChartType = Enums.ChartType.LogarithmLine;
this.chart1.ChartArea.Data = this.dsTest1.Tables[0];
this.chart1.ChartArea.XValueMember = "F_X";
this.chart1.ChartArea.BaseNumber = 10;

StringInfo chartTitle
= new StringInfo();
chartTitle.Value
= "LogarithmLineChart";
chartTitle.Color
= Color.DarkBlue;
chartTitle.Size
= 15;
this.chart1.ChartArea.ChartTitle = chartTitle;

this.chart1.ChartArea.AxisLineColor = Color.DarkSeaGreen;

StringInfo axisXLable
= new StringInfo();
axisXLable.Size
= 12;
axisXLable.Color
= Color.Silver;
axisXLable.Value
= "时间";
this.chart1.ChartArea.AxisX.Lable = axisXLable;

this.chart1.ChartArea.AxisX.Interval = 0.5;
this.chart1.ChartArea.AxisX.IntervalType = Enums.InervalType.Hours;
this.chart1.ChartArea.AxisX.TimeFormat = "MM-dd HH:mm";
this.chart1.ChartArea.AxisX.MinVAlue = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0).ToOADate();

this.chart1.ChartArea.AxisY1.Grid.LineColor = Color.RosyBrown;
this.chart1.ChartArea.AxisY1.Grid.LineStyle = Enums.LineStyle.DashDot;
this.chart1.ChartArea.AxisY1.ShowGrid = true;
this.chart1.ChartArea.AxisY1.MinVAlue = 0.001;

StringInfo axisYLable
= new StringInfo();
axisYLable.Size
= 12;
axisYLable.Color
= Color.Silver;
axisYLable.Value
= "数据";
this.chart1.ChartArea.AxisY1.Lable = axisYLable;

this.chart1.ChartArea.AxisY1.Interval = 1;
this.chart1.ChartArea.AxisY1.IntervalType = Enums.InervalType.Number;

Series series1
= new Series();
series1.Name
= "SeriesOne";
series1.Color
= Color.Sienna;
series1.Width
= 1;
series1.YValueMember
= "F_Y2";
this.chart1.ChartArea.Series.Add(series1);

PartingLine line
= new PartingLine();
line.LineColor
= Color.RosyBrown;
line.LineWidth
= 2;
line.YValue
= 1500;
this.chart1.ChartArea.PartingLines.Add(line);
}

 

  此外,还有对数点图和对数区域图,都差不多,不再赘述
     点击下载项目

相关文章推荐

使用WinForm Chart控件 制作饼装,柱状,折线图

chart控件的属性很多,主要用到Chart控件图表区域的属性有五个属性 1.Annotations :批注集合(我没怎么用到,但是配置的话会在图标区域出现一些可以备注的东西吧) 2.ChartAr...

C# WinForm开发系列之chart控件画折线图和柱形图并自定义鼠标移动到数据标记点显示提示信息

1.首先拖动chart控件到窗体,设置chart1的属性Legends中默认的Legend1的Enable为false; 2.设置Series的ChartType为Line 3.后台绑定数据 ...

Winform Chart控件绘制阴影区域

先来看看效果 公司电力项目需要绘制这种工业图表,之前同事用Series绘制的 有点麻烦 需要计算起始点位置,后来我发现Chart控件本来就提供了这种阴影属性,简单方便 直接上代码 pr...

WinForm Chart控件使用记录(由于制作饼装,柱状,折线图)

由于公司的winform项目需要用到Chart图表,抽空研究了一下,特地发上来给大家做个参考,就目前而言用到的属性说明都做了注释;主要用到Chart控件图表区域的属性有五个属性 Annotation...

C# Winform Chart控件使用

稍微总结下 C# 的Winform 中 chart 控件使用踩过的坑。同时,希望能对于其他控件的使用有一定的参考性。

winform chart控件 案例

工具: freamwork   3.5 版本  vs2010   sql2008  小女刚刚学习winform报表,如果做的有什么不对的,还望大N们指点指点,嘻嘻   代码部分: namesp...

分享一个Winform下的分页控件

分享一个Winform下的分页控件。如有反馈,请联系邀月。3w@live.cn
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)