private void button1_Click(object sender, EventArgs e) { //清除Series chart1.Series.Clear(); Random randon = new Random(); //添加第一个Series chart1.Series.Add("2017年销售"); chart1.Series[0].Points.Clear(); chart1.Series[0].Points.AddXY("1月", randon.Next(50,500)); chart1.Series[0].Points.AddXY("2月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("3月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("4月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("5月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("6月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("7月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("8月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("9月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("10月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("11月", randon.Next(50, 500)); chart1.Series[0].Points.AddXY("12月", randon.Next(50, 500)); //添加第二个Series chart1.Series.Add("2018年销售"); chart1.Series[1].Points.Clear(); chart1.Series[1].Points.AddXY("1月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("2月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("3月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("4月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("5月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("6月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("7月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("8月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("9月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("10月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("11月", randon.Next(50, 500)); chart1.Series[1].Points.AddXY("12月", randon.Next(50, 500)); }
效果