1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace 图表练习 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Series series1 = new Series(); series1 = chart1.Series[0]; series1.ChartType = SeriesChartType.Spline; series1.BorderWidth = 2; series1.Color = Color.Red; series1.LegendText = "第一条线"; Series series2 = new Series(); series2 = chart1.Series[1]; series2.ChartType = SeriesChartType.Line; series2.BorderWidth = 2; series2.Color = Color.Green; series2.LegendText = "第二条线"; int[] myValues1 = { 3, 4, 5, 6, 7, 8, 8, 4, 3, 2, 9, 6, 8, 4, 2, 9, 1, 2, 5, 6, 8, 9, 1, 2, 3, 4, 4, 8 }; int[] myValues2 = { 13, 13, 14, 15, 16, 17, 18, 19, 10, 14, 17, 19, 14, 13, 19, 11, 12, 15, 16, 17, 19, 11 }; int xValue1 = 0; int xValue2 = 0; foreach (int yValue1 in myValues1) { series1.Points.AddXY(xValue1, yValue1); xValue1++; } foreach (int yValue2 in myValues2) { series2.Points.AddXY(xValue2, yValue2); xValue2++; } ChartArea myChartArea = chart1.ChartAreas[0]; myChartArea.AxisX.Minimum = 0; myChartArea.AxisX.Maximum = 30; myChartArea.AxisY.Minimum = 0; myChartArea.AxisY.Maximum = 20; } } }
|