1、安装MSChart控件
VS2008在默认下是没有MSChart控件,所以我们需要下载安装。
Chart For vs2008安装需要下载4个文件:
(1)dotnetfx35setup.exe
(2)MSChart_VisualStudioAddOn.exe
(3)MSChartLP_chs.exe
(4)MSChart.exe
http://iask.sina.com.cn/u/ish
然后分别安装,安装结束之后打开VS2008就可以在工具箱中看到Chart图表控件:
http://s8/middle/873a233exab2538fe7e57&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
2、添加MSChart控件
为WinForm窗体添加Chart控件
http://s2/middle/873a233exab25470eb0f1&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
3、设置MSChart控件的属性
设置MSChart控件属性方法两种:1、代码中设置属性;2、属性表设置属性
1、代码中设置属性
步骤1:添加引用
using
System.Windows.Forms.DataVisualization.Charting;
步骤2:写入代码
namespace
MSChart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs
e)
{
////////////////////ChartArea1属性设置///////////////////////////
//设置网格的颜色
chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor
= Color.LightGray;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor
= Color.LightGray;
//设置坐标轴名称
chart1.ChartAreas["ChartArea1"].AxisX.Title = "随机数";
chart1.ChartAreas["ChartArea1"].AxisY.Title = "数值";
//启用3D显示
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
//////////////////////Series属性设置///////////////////////////
//设置显示类型-线型
chart1.Series["随机数"].ChartType = SeriesChartType.Line;
//设置坐标轴Value显示类型
chart1.Series["随机数"].XValueType = ChartValueType.Time;
//是否显示标签的数值
chart1.Series["随机数"].IsValueShownAsLabel = true;
//设置标记图案
chart1.Series["随机数"].MarkerStyle = MarkerStyle.Circle;
//设置图案颜色
chart1.Series["随机数"].Color = Color.Green;
//设置图案的宽度
chart1.Series["随机数"].BorderWidth = 3;
//添加随机数
Random rd = new Random();
for (int i = 1; i < 20; i++)
{
chart1.Series["随机数"].Points.AddXY(i, rd.Next(100));
}
}
}
}
http://s11/middle/873a233exab256e0dfe3a&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
2、属性表设置属性
步骤1:设置ChartArea属性
http://s10/middle/873a233exab2579cb4799&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
点击ChartAreas(集合)后面的小按钮进入对话框,设置对应的属性
http://s2/middle/873a233ex7783c0646f71&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
步骤2:设置Series属性
点击Series(集合)后面的小按钮进入对话框,设置对应属性
http://s1/middle/873a233exab2591a36f20&690MSChart图表控件使用介绍" TITLE="C# MSChart图表控件使用介绍" />
以此方法还可以设置:Annotations注解(集合)属性;Legends图例(集合)属性;Titles标题(集合)属性。
加载中,请稍候......