public void print()
{
string sql="select lie2 from xtsd where lie1='xsbg'";
ds.Clear();
ds=objbase.ExecSelect(sql,"xtsd");
if(ds.Tables[0].Rows.Count>0)
{
this.Txt_xsbg.Text=ds.Tables[0].Rows[0]["lie2"].ToString();
this.xsbg=Int32.Parse(ds.Tables[0].Rows[0]["lie2"].ToString().Trim());
}
sql="select lie2 from xtsd where lie1='xsbm'";
ds.Clear();
ds=objbase.ExecSelect(sql,"xtsd");
if(ds.Tables[0].Rows.Count>0)
{
this.Txt_xsbm.Text=ds.Tables[0].Rows[0]["lie2"].ToString();
this.xsbm=Int32.Parse(ds.Tables[0].Rows[0]["lie2"].ToString().Trim());
}
this.axMSChart1.Title.Text="駕駛員出車公里數與出發費用按比例顯示柱狀圖(公里象素比:100:"+this.Txt_xsbg.Text.Trim()+" 出發費象素比:100:"+this.Txt_xsbm.Text.Trim()+")";
sql="select * from driverinfo";
ds.Clear();
ds=objbase.ExecSelect(sql,"driverinfo");
if(ds.Tables[0].Rows.Count>0)
{
Object[,] myay=new Object[ds.Tables[0].Rows.Count,2];
string[,] xinxi=new string[ds.Tables[0].Rows.Count,2];
//Object[,,] myay=new Object[ds.Tables[0].Rows.Count,ds.Tables[0].Rows.Count,2];
//myay[0,0]="時間描述";//這裏可以不用寫什麼
//myay[0,1]="壓力描述";//這裏是描述座標點的壓力
DataSet dsl=new DataSet();
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
string jsybh=ds.Tables[0].Rows[i]["jsybh"].ToString().Trim();
string xm=ds.Tables[0].Rows[i]["xm"].ToString().Trim();
if(ChuanZ.cs.Trim()=="出")
{
sql="select sum(xsgl) xsgl,sum(cff) cff from pcgl where jsybh='"+jsybh+"' and ccriqi>='"+ChuanZ.datestart.Trim()+"' and ccriqi<='"+ChuanZ.dateend.Trim()+"'";
}
if(ChuanZ.cs.Trim()=="收")
{
sql="select sum(xsgl) xsgl,sum(cff) cff from pcgl where jsybh='"+jsybh+"' and scriqi>='"+ChuanZ.datestart.Trim()+"' and scriqi<='"+ChuanZ.dateend.Trim()+"'";
}
if(ChuanZ.cs.Trim()=="")
{
int year=System.DateTime.Now.Year;
int month=System.DateTime.Now.Month;
string start=year.ToString()+"-"+month.ToString()+"-1";
sql="select sum(xsgl) xsgl,sum(cff) cff from pcgl where jsybh='"+jsybh+"' and ccriqi>='"+start+"' ";
}
dsl.Clear();
dsl=objbase.ExecSelect(sql,"money");
// int heightg=0;
// int heightm=0;
try
{
myay[i,0]=(Object)((Int32.Parse(dsl.Tables[0].Rows[0]["xsgl"].ToString().Trim())/100.0)*xsbg).ToString();
myay[i,1]=(Object)((Int32.Parse(dsl.Tables[0].Rows[0]["cff"].ToString().Trim())/100.0)*xsbm).ToString();
xinxi[i,0]=dsl.Tables[0].Rows[0]["xsgl"].ToString().Trim();
xinxi[i,1]=dsl.Tables[0].Rows[0]["cff"].ToString().Trim();
}
catch
{
myay[i,0]="0";
myay[i,1]="0";
xinxi[i,0]="0";
xinxi[i,1]="0";
}
//這裏是個重點,爲什麼要加上"["+"]"
//其實這個axMSChart1玩意很有意識的,如果你的字符串是數字類型的描述
//就算是字符串類型也不會當成橫座標哦!!
//嘿嘿有意識把,本人曾經爲了這個問題搞了幾天的!
//myay[i,0]=(Object)dsl.Tables[0].Rows[0]["xsgl"].ToString();
//myay[i,1]=(Object)dsl.Tables[0].Rows[0]["cff"].ToString();
}
//設計axMSChart1的數據
axMSChart1.ChartData = myay;
this.axMSChart1.FootnoteText="實際公里數、出發費:";
for(short i=1;i<=this.axMSChart1.RowCount;i++)
{
this.axMSChart1.Row=i;
this.axMSChart1.RowLabel=ds.Tables[0].Rows[i-1]["xm"].ToString();//+"("+xinxi[i-1,0].Trim()+","+xinxi[i-1,1].Trim()+")";
this.axMSChart1.FootnoteText=this.axMSChart1.FootnoteText+ds.Tables[0].Rows[i-1]["xm"].ToString()+"("+xinxi[i-1,0].Trim()+","+xinxi[i-1,1].Trim()+") ";
}
this.axMSChart1.Column=1;
this.axMSChart1.ColumnLabel="公里數";
this.axMSChart1.Column=2;
this.axMSChart1.ColumnLabel="出發費";
//MessageBox.Show(this.axMSChart1.RowLabel[1].ToString());
//this.axMSChart1.RowLabel[
// //設計圖表的表頭名稱和對齊方式
// axMSChart1.Title.Text = "這裏是一個圖表";
//
// axMSChart1.Legend.Location.LocationType = MSChart20Lib.VtChLocationType.VtChLocationTypeRight;
//
// axMSChart1.Legend.Location.Visible = true;
//
//
// //設計X軸名稱
// axMSChart1.Plot.get_Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX, null).AxisTitle.Text = "這裏是時間描述";
//
// //設計Y軸名稱
// axMSChart1.Plot.get_Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY, null).AxisTitle.Text = "這裏是壓力描述";
//設計圖表形狀的描述方式,是並圖還是線圖等等
//axMSChart1.chartType = MSChart20Lib.VtChChartType.VtChChartType2dLine;
ds.Clear();
}
}
參考帖子:http://community.csdn.net/Expert/topic/5064/5064877.xml?temp=.8670008,hzjlltj() 得回覆