//按钮加载K线
private void button1_Click(object sender, EventArgs e)
{
int count = int.Parse(this.comboBox1.Text.Trim());
half = count;
string jintian = DateTime.Now.ToShortDateString().ToString();
curdate = jintian;
begindate = jintian;
this.Refresh();
string sql = “select top " + count + " begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301 where begintime<=’” + jintian + “’ order by begintime desc”;
huatu(sql, count);
label1.Text = curdate;
}
//画K线方法
private void huatu(string sql,int num)
{
Graphics g = CreateGraphics();
Pen p = new Pen(Color.Red, 1);//上涨
Pen p1 = new Pen(Color.Green, 1);//下跌
Pen p2 = new Pen(Color.Black, 1);
Pen p3 = new Pen(Color.Blue, 1);
Point[] pointList5;//用来绘制曲线图的关键点,依次将这些点连接起来即得到曲线图(Ma5)
Point[] pointList10;
DataSet ds = null;
DataTable dt = null;
ds = db.getds(sql, “mminfo”);
dt = ds.Tables[0];
pointList5 = new Point[dt.Rows.Count];//初始化坐标数组
pointList10 = new Point[dt.Rows.Count];//初始化坐标数组
int width = 1050;
int height = 400;
int Kwidth = width / dt.Rows.Count - 10;
g.DrawRectangle(p, 80, 80, width, height);
//k线开始
Font myFont = new Font(“微软雅黑”, 8);
string begindate1 = null;
string overdate1=dt.Rows[dt.Rows.Count-1][“begintime”].ToString();
overdate =overdate1.Substring(0,overdate1.IndexOf(" “));
string begindate2 = dt.Rows[0][“begintime”].ToString();
begindate = begindate2.Substring(0, begindate2.IndexOf(” "));
decimal high = (decimal)dt.Compute(“Max(dayhigh)”, null);//选择的K线组合中最高价
decimal low = (decimal)dt.Compute(“Min(daylow)”, null);//选择的K线组合中最低价
decimal hhigh = Math.Floor(high);
decimal llow = Math.Floor(low);
float llow1 = float.Parse(llow.ToString());
int changdu = width / dt.Rows.Count;//横轴每个日期的长度
decimal hlow = hhigh - llow;//纵轴总共差价
decimal oneprice = hlow / 10;
float onepoint = float.Parse((height / hlow).ToString());//单个价格所占的纵轴坐标
for (int i = 0; i < dt.Rows.Count; i++)//横轴时间
{
g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height + 80, width +
C#画K线实现加载均线(5日,10日)
最新推荐文章于 2024-04-20 09:19:25 发布