本文介绍了在MS Chart C#.net中动态创建系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是C#和.Net的新手,我在创建的MS图表中遇到了问题。我已经搜索过并找到了这个问题的答案,但是我已经正确地实现了回复,所以我想,我仍然无法让它工作。该图表仅显示数组的最终系列(组[3])。我的代码如下: I''m new to C# and .Net and am facing a problem within an MS chart I''ve created. I''ve searched and found answers to this question already, but although I have implemented the replies correctly, so I thought, I still have not been able to get it to work. The chart displays only the final series of the array (groups[3]). My code is as follows:string[] groups = new string[5]; groups[0] = "MD"; groups[1] = "SR"; groups[2] = "TS"; groups[3] = "WS"; System.Drawing.Color[] clrs = new System.Drawing.Color[5]; clrs[0] = System.Drawing.Color.Red; clrs[1] = System.Drawing.Color.Green; clrs[2] = System.Drawing.Color.MediumPurple; clrs[3] = System.Drawing.Color.Blue; clrs[4] = System.Drawing.Color.Orange; Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = 0; Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = 96; Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; Chart1.ChartAreas["ChartArea1"].AxisY.Minimum = 0; Chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 400; Chart1.ChartAreas["ChartArea1"].AxisY.Interval = 50; for (int cnt = 0; cnt < 4; cnt++) { com2.CommandText = ""; com2.CommandText = "SELECT left(convert(varchar,Date,106),6) + char(10) as Date, occupancy FROM occupancy_projection WHERE specialtygroup = '" + groups[cnt] + "' order by convert(date,Date)"; SqlDataReader reader = com2.ExecuteReader(); Series aSeries = new Series(); aSeries.Name = groups[cnt]; Chart1.Series.Add(aSeries[cnt]); Chart1.Series[cnt].ChartType = SeriesChartType.Line; Chart1.Series[cnt].BorderWidth = 2; Chart1.Series[cnt].MarkerStyle = MarkerStyle.Circle; Chart1.Series[cnt].XValueMember = "Date"; Chart1.Series[cnt].YValueMembers = "occupancy"; Chart1.Series[cnt].Color = clrs[cnt]; //Chart1.Series[cnt].Legend = "Legend1"; Chart1.DataSource = reader; Chart1.DataBind(); reader.Close(); } com.Dispose(); con.Close(); } 我想知道是否有人可以在这里指出我的错误? 谢谢 Steve I wonder if anyone can point out my error(s) here?ThanksSteve推荐答案 这篇关于在MS Chart C#.net中动态创建系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 15:04