string begindate = null;
string curdate = null;
string overdate = null;
int half = 0;
string gpname = null;
int width = 1050;//K线图矩形宽
int height = 400;//K线图矩形高
int leftX = 40;//k线图矩形原始坐标X
int topY = 80;//k线图矩形原始坐标Y
//按钮加载K线
private void button1_Click(object sender, EventArgs e)
{
if (this.comboBox1.Text == “热点”)
{
gpname = “zhy” + this.textBox1.Text.Trim();
}
else
{
gpname =this.textBox1.Text.Trim();
}
if (gpname != “zhy”)
{
int count = 10;
half = count;
//string jintian = DateTime.Now.ToShortDateString().ToString();
string jintian = this.dateTimePicker1.Text;
curdate = jintian;
begindate = jintian;
this.Refresh();
string sql = “select top " + count + " begintime,dayopen,dayclose,dayhigh,daylow,day5,day10,day20,day60 from " + gpname + " where begintime<=’” + jintian + “’ order by begintime desc”;
huatu(sql, count);
label1.Text = curdate;
this.textBox1.Text = “”;
}
}
//画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.Brown, 1);
Pen p4 = new Pen(Color.Purple, 1);
Pen p5 = new Pen(Color.Blue, 1);
Point[] pointList5;//用来绘制曲线图的关键点,依次将这些点连接起来即得到曲线图(Ma5)
Point[] pointList10;//(Ma10)
Point[] pointList20;//(Ma20)
Point[] pointList60;//(Ma60)
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];//初始化坐标数组
pointList20 = new Point[dt.Rows.Count];//初始化坐标数组
pointList60 = new Point[dt.Rows.Count];//初始化坐标数组
int Kwidth = width / dt.Rows.Count - 10;
g.DrawRectangle(p, leftX, topY, 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 + leftX - changdu *