1 using System.Windows.Forms.DataVisualization.Charting; //chart画图此引用必不可少
2
3 private void Form3_Load(object sender, EventArgs e)
4 {
5 int[] arrt = new int[] { 94, 52, 25, 67, 91, 56, 21, 77, 99, 56, 26, 77, 69, 56, 29, 37 };
6 draw(arrt);
7 }
8
9 /// <summary>画折线图的方法
10 /// </summary>
11 /// <param name="arr">条形值数组参数</param>
12 public void draw(int[] arr)
13 {
14 chart1.Series.Clear(); //清除默认的Series
15 Series Strength = new Series("力量"); //new 一个叫做【Strength】的系列
16 Strength.ChartType = SeriesChartType.Spline; //设置chart的类型,spline样条图 Line折线图
17 Strength.IsValueShownAsLabel = true; //把值当做标签展示(默认false)
18 chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 1; //设置网格间隔(这里设成0.5,看得更直观一点)
19 ////chart1.ChartAreas[0].AxisX.Maximum = 100;//设定x轴的最大值
20 //chart1.ChartAreas[0].AxisY.Maximum = 100;//设定y轴的最大值
21 //chart1.ChartAreas[0].AxisX.Minimum = 0;//设定x轴的最小值
22 //chart1.ChartAreas[0].AxisY.Minimum = 0;//设定y轴的最小值
23 chart1.ChartAreas[0].AxisY.Interval = 10; //设置Y轴每个刻度的跨度
24 //给系列上的点进行赋值,分别对应横坐标和纵坐标的值
25 for (int i = 1; i <= arr.Length; i++)
26 {
27 Strength.Points.AddXY(i, arr[i - 1]);
28 }
29 //把series添加到chart上
30 chart1.Series.Add(Strength);
31 }