在MS Chart C#.net中动态创建系列 [英] Dynamically create series in MS Chart C#.net

查看:82
本文介绍了在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?

Thanks

Steve

推荐答案

回答我自己的问题,这是不是如上所述的问题的解决方案,但它通过解决方法解决了问题:我通过使存储过程转动它来改变数据的配置,以便我能够从表中为每个系列分配一列。我仍然很想知道为什么上面的代码不起作用!



我现在有另外一个关于Chart Series的问题,我将单独发布。< br $>




问候



Steve
Answering my own question, this is not a solution to the problem as stated, but it solved the issue by means of a workaround: I altered the configuration of the data by getting the stored procedure to pivot it so that I was able to assign a column from the table to each series. I''m still curious to know why the above code didn''t work though!

I now have another question about Chart Series which I will post separately.


Regards

Steve


这篇关于在MS Chart C#.net中动态创建系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆