使用AxMSChart20Lib.AxMSChart显示图表

来源:互联网 发布:服务端源码是什么 编辑:程序博客网 时间:2024/05/02 04:33

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() 得回复