none
Chart 股票图中的移动平均线问题(附代码) RRS feed

  • 问题

  • 我现在正在做一个股票走势图,基本的显示以经做好,但我现在要做移动平均线就不知道怎样做了.我现在有高,底,开,收这四个价.我知道移动平均线是用N天想加除以N.也就是说5天移动平均线就是(N1+N2+N3+N4+N5)/5下一天就是(N2+N3+N4+N5+N6)/5.但我的图表都是直接读取数据库数据进行绑定的.我现在添加一个Series用来做移动平均线.但我不知如何做了.希望各位能帮帮我.下面附上我做好的代码:

    string Strsql = "select * from (select top 60 PRO_CODE,CONVERT(varchar(100),date, 111) as Date,[OPEN],HIGH,LOW,[CLOSE] from HLOC order by date desc) as Data order by Date asc";
                SQLServerHelp cs = new SQLServerHelp();
                DataSet ds = cs.sqlSelectDS(Strsql);
                Chart1.DataSource = ds;
                Chart1.Series["Series1"].XValueMember = "Date";
                Chart1.Series["Series1"].YValueMembers = "HIGH,LOW,OPEN,CLOSE";
                Chart1.Series["Series1"].ToolTip = "Date\t= #VALX\nHight\t= #VALY\nLow\t= #VALY2\nOpen\t= #VALY3\nClose\t= #VALY4";
                Chart1.DataBind();
                string strsql = "select min(LOW) as LOW,max(HIGH) as HIGH from(select top 60 CONVERT(varchar(100),date, 111) as Date,[OPEN],HIGH,LOW,[CLOSE] from HLOC order by date desc) AS Data";
                SQLServerHelp CS = new SQLServerHelp();
                DataSet DS = CS.sqlSelectDS(strsql);
                string Mini = DS.Tables[0].Rows[0]["LOW"].ToString();
                double Minimum = Convert.ToDouble(Mini);
                string High = DS.Tables[0].Rows[0]["HIGH"].ToString();
                double HIGH = Convert.ToDouble(High);
                string PName = ds.Tables[0].Rows[0]["PRO_CODE"].ToString();
                Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = 61;
                Chart1.ChartAreas["ChartArea1"].AxisY.Minimum = Minimum - 30;
                Chart1.ChartAreas["ChartArea1"].AxisY.Maximum = HIGH + 30;
                Chart1.Titles["Title1"].Text = PName;

    这个是所做好效果,就差移动平均线了.http://b39.photo.store.qq.com/http_imgload.cgi?/rurl4_b=65863f36ef416219bc91d88e022c6f8a44c879f7e2f0ffd17dfdd14b23700762087b3fa12e1bcec9cebd6606479d280d2ed59e56169cc9ae4a3580153617c7ba0d967d76fb7bda512932a80b342c3b9280109a4a&a=36&b=39

    2010年6月25日 8:39

全部回复