乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp.net統(tǒng)計(jì)圖控件dotnetCHARTING用法

       悟靜 2011-12-16

      using System;
      using System.Data;
      using System.Configuration;
      using System.Collections;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Web.UI.HtmlControls;
      using System.Data.SqlClient;
      using System.Drawing;
      using dotnetCHARTING;


      public partial class tongjitu2 : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {

            if(!isPostBack)

              {

                Drawing();

               }
           }

      private void Drawing()
          {
              Charting c = new Charting();
              c.Title = "商品價(jià)格走勢(shì)圖";
              c.XTitle = "月份";
              c.YTitle = "價(jià)格(元)";
              c.PicHight = 350;
              c.PicWidth = 650;
              c.SeriesName = "合計(jì)";//僅對(duì)于DataTable類型做數(shù)據(jù)源時(shí),此屬性有效
              c.PhaysicalImagePath = "ChartImages";//統(tǒng)計(jì)圖片存放的文件夾名稱,缺少對(duì)應(yīng)的文件夾生成不了統(tǒng)計(jì)圖片
              c.FileName = "Statistics";
              c.Type = SeriesType.Spline;//折線型
              c.Use3D = false;
              c.DataSource = GetDataSource();
              c.CreateStatisticPic(this.Chart1);

          }

          private DataTable GetDataSource()
          {
              DataTable MyTable = new DataTable();
              try
              {
                  SqlConnection conn = new SqlConnection("server=.;database=demo;uid=sa;pwd=;");
                  string sqlstr = "select month ,xiaoliang from t_result ";
                  conn.Open();
                  DataSet ds = new DataSet();
                  SqlCommand cmd = new SqlCommand();
                  cmd.CommandText = sqlstr;
                  SqlDataAdapter sqlda = new SqlDataAdapter(sqlstr, conn);
                  sqlda.Fill(ds);
                  if (ds != null && ds.Tables.Count > 0)
                  {
                      MyTable = ds.Tables[0];
                  }
                  return MyTable;

              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message);
                  throw;
              }
          }


      }

      ==============================================================================

      using System;
      using System.Data;
      using System.Configuration;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Web.UI.HtmlControls;
      using dotnetCHARTING;

      /// <summary>
      /// Charting的摘要說明
      /// </summary>
      public class Charting
      {
          protected string _phaysicalimagepath;
          protected string _title;
          protected string _xtitle;
          protected string _ytitle;
          protected string _seriesname;
          protected int _picwidth;
          protected int _pichight;
          protected SeriesType _type;
          protected bool _use3d;
          protected DataTable _dt;
          protected string _filename;

      public Charting()
      {
         //
         // TODO: 在此處添加構(gòu)造函數(shù)邏輯
         //
      }
              /// <summary>
              /// 圖片存放路徑
              /// </summary>
              public string PhaysicalImagePath
              {
                  set { _phaysicalimagepath = value; }
                  get { return _phaysicalimagepath; }
              }
              /**/
              /// <summary>
              /// 圖片標(biāo)題
              /// </summary>
              public string Title
              {
                  set { _title = value; }
                  get { return _title; }
              }
              /**/
              /// <summary>
              /// 圖片x座標(biāo)名稱
              /// </summary>
              public string XTitle
              {
                  set { _xtitle = value; }
                  get { return _xtitle; }
              }
              /**/
              /// <summary>
              /// 圖片y座標(biāo)名稱
              /// </summary>
              public string YTitle
              {
                  set { _ytitle = value; }
                  get { return _ytitle; }
              }

              /**/
              /// <summary>
              /// 圖例名稱
              /// </summary>
              public string SeriesName
              {
                  set { _seriesname = value; }
                  get { return _seriesname; }
              }
              /**/
              /// <summary>
              /// 圖片寬度
              /// </summary>
              public int PicWidth
              {
                  set { _picwidth = value; }
                  get { return _picwidth; }
              }
              /**/
              /// <summary>
              /// 圖片高度
              /// </summary>
              public int PicHight
              {
                  set { _pichight = value; }
                  get { return _pichight; }
              }

              /// <summary>
              /// 統(tǒng)計(jì)圖類型(柱形,線形等)
              /// </summary>
              public SeriesType Type
              {
                  set { _type = value; }
                  get { return _type; }
              }

              /// <summary>
              /// 是否將輸出的圖片顯示成三維
              /// </summary>
              public bool Use3D
              {
                  set { _use3d = value; }
                  get { return _use3d; }
              }

              /// <summary>
              /// 對(duì)比圖形數(shù)據(jù)源
              /// </summary>
              public DataTable DataSource
              {

                  set { _dt = value; }
                  get { return _dt; }
              }

              /// <summary>
              /// 生成統(tǒng)計(jì)圖片的名稱
              /// </summary>
              public string FileName
              {
                  set { _filename = value; }
                  get { return _filename; }
              }

              /// <summary>
              /// 生成單一統(tǒng)計(jì)圖片
              /// </summary>
              /// <param name="chart"></param>
              /// <param name="type">圖形類別,如柱狀,折線型</param>
              public void CreateStatisticPic(dotnetCHARTING.Chart chart)
              {
                  chart.Title = this.Title;
                  chart.XAxis.Label.Text = this.XTitle;
                  chart.YAxis.Label.Text = this.YTitle;
                  chart.TempDirectory = this.PhaysicalImagePath;
                  chart.FileManager.FileName = this.FileName;
                  chart.Width = this.PicWidth;
                  chart.Height = this.PicHight;
                  chart.Type = ChartType.Combo;
                  chart.Series.Type = this.Type;
                  chart.Series.Name = this.SeriesName;
                  chart.Series.Data = this.DataSource;
                  chart.SeriesCollection.Add();
                  chart.DefaultSeries.DefaultElement.ShowValue = true;
                  chart.ShadingEffect = true;
                  chart.Use3D = this.Use3D;
                  chart.Series.DefaultElement.ShowValue = true;
              }
      }

      using System;
      using System.Data;
      using System.Configuration;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Web.UI.HtmlControls;
      using System.Drawing.Imaging;
      using System.Drawing;

      /// <summary>
      /// DrawingCurve 的摘要說明
      /// </summary>
      public class DrawingCurve
      {
         
          public int intXLong = 800;   //圖片大小 長(zhǎng)
          public int intYLong = 600;   //圖片大小 高
          public int intXMultiple = 1;    //零刻度的值 X
          public int intYMultiple = 0;    //零刻度的值 Y
          public int intXMax = 12;    //最大刻度(點(diǎn)數(shù)) X
          public int intYMax = 30;    //最大刻度(點(diǎn)數(shù)) Y

          public int intLeft = 50;   //左邊距
          public int intRight = 120; //右邊距
          public int intTop = 30;    //上邊距
          public int intEnd = 50;    //下邊距

          public string strXText = "時(shí)間(單位:月)";    //單位 X
          public string strYText = "數(shù)量(單位:個(gè))";    //單位 Y
          public string strTitle = "趨勢(shì)線圖";    //標(biāo)題
          public DataTable tbData;    //要統(tǒng)計(jì)的數(shù)據(jù)


          private int intXScale = 30;    //一刻度長(zhǎng)度 X
          private int intYScale = 30;    //一刻度高度 Y
          //private int intX = 0;   //0點(diǎn) X坐標(biāo)
          //private int intY = 0;   //0點(diǎn) Y坐標(biāo)
          public int intData = 0;    //記錄數(shù)

          public DrawingCurve()
          {

              intXScale = (intXLong - intLeft - intRight) / (intXMax + 1);//一刻度長(zhǎng)度 X
              intYScale = (intYLong - intTop - intEnd) / (intYMax + 1);//一刻度高度 Y

              //intX = intXLong - intLeft;   //0點(diǎn) X坐標(biāo)
              //intY = intYLong - intEnd;   //0點(diǎn) Y坐標(biāo)
          }

          public Bitmap DrawingImg()
          {

              Bitmap img = new Bitmap(intXLong, intYLong); //圖片大小
              Graphics g = Graphics.FromImage(img);
              g.Clear(Color.Snow);
              g.DrawString(strTitle, new Font("宋體", 14), Brushes.Black, new Point(5, 5));
              g.DrawLine(new Pen(Color.Black, 2), intLeft, intYLong - intEnd, intXLong - intRight, intYLong - intEnd); //繪制橫向
              g.DrawLine(new Pen(Color.Black, 2), intLeft, intTop, intLeft, intYLong - intEnd);   //繪制縱向

              //繪制縱坐標(biāo)
              g.DrawString(strYText, new Font("宋體", 12), Brushes.Black, new Point(intLeft, intTop));//Y 單位
              Point p1 = new Point(intLeft - 10, intYLong - intEnd);
              for (int j = 0; j <= intYMax; j++)
              {
                  p1.Y = intYLong - intEnd - j * intYScale;
                  Point pt = new Point(p1.X + 10, p1.Y);
                  //繪制縱坐標(biāo)的刻度和直線
                  g.DrawLine(Pens.Black, pt, new Point(p1.X + 15, p1.Y));
                  //繪制縱坐標(biāo)的文字說明
                  g.DrawString(Convert.ToString(j + intYMultiple), new Font("宋體", 12), Brushes.Black, new Point(p1.X - 25, p1.Y - 8));
              }

              //繪制橫坐標(biāo)
              g.DrawString(strXText, new Font("宋體", 12), Brushes.Black, new Point(intXLong - intRight, intYLong - intEnd));//X 單位
              Point p = new Point(intLeft, intYLong - intEnd);
              for (int i = 0; i < intXMax; i++)
              {
                  p.X = intLeft + i * intXScale;
                  //繪制橫坐標(biāo)刻度和直線
                  g.DrawLine(Pens.Black, p, new Point(p.X, p.Y - 5));
                  //繪制橫坐標(biāo)的文字說明
                  g.DrawString(Convert.ToString(i + intXMultiple), new Font("宋體", 12), Brushes.Black, p);
              }


              intData = tbData.Rows.Count;
              if (intData > 0)
              {
                  //趨勢(shì)線圖
                  for (int i = 0; i < intData - 1; i++)
                  {
                      DataRow Row1 = tbData.Rows[i];
                      DataRow Row2 = tbData.Rows[i + 1];
                      //定義起點(diǎn)
                      Point rec = new Point(Convert.ToInt32(intLeft + ((TurnNumber(Row1[0].ToString()) - intXMultiple) * intXScale)), Convert.ToInt32(intYLong - intEnd - (TurnNumber(Row1[1].ToString()) - intYMultiple) * intYScale));
                      //定義終點(diǎn)
                      Point dec = new Point(Convert.ToInt32(intLeft + ((TurnNumber(Row2[0].ToString()) - intXMultiple) * intXScale)), Convert.ToInt32(intYLong - intEnd - (TurnNumber(Row2[1].ToString()) - intYMultiple) * intYScale));
                      //繪制趨勢(shì)折線
                      g.DrawLine(new Pen(Color.Red), rec, dec);
                  }
              }

              return img;
          }

          //轉(zhuǎn)換數(shù)字
          private double TurnNumber(string str)
          {
              double dubReturn;
              try
              {
                  dubReturn = Convert.ToDouble(str);
              }
              catch
              {
                  dubReturn = 0;
              }
              return dubReturn;

          }

      }

      ----------------------------------調(diào)用------------------------------------------------

      protected void Page_Load(object sender, EventArgs e)
          {
              DataTable MyTable = new DataTable();
             

              //string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/db.mdb");
              //string cmdstr = "SELECT 月份,銷量 FROM Result";
              //OleDbConnection con = new OleDbConnection(constr);
              //con.Open();
              //OleDbCommand cmd = new OleDbCommand(cmdstr, con);
              //OleDbDataAdapter da = new OleDbDataAdapter(cmdstr, con);
              //da.Fill(MyTable);

            //sql數(shù)據(jù)庫
              try
              {
                  SqlConnection conn = new SqlConnection("server=.;database=demo;uid=sa;pwd=;");
                  string sqlstr = "select month ,xiaoliang from t_result ";
                  conn.Open();
                  DataSet ds = new DataSet();
                  SqlCommand cmd = new SqlCommand();
                  cmd.CommandText = sqlstr;
                  SqlDataAdapter sqlda = new SqlDataAdapter(sqlstr, conn);
                  sqlda.Fill(ds);
                  if (ds != null && ds.Tables.Count > 0)
                  {
                      MyTable = ds.Tables[0];
                  }
                
                 
              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message);
                  throw;
              }

              DrawingCurve MyDc = new DrawingCurve();
              MyDc.tbData = MyTable;

              Bitmap img = new Bitmap(100, 100);
              img = MyDc.DrawingImg();
              Graphics g = Graphics.FromImage(MyDc.DrawingImg());

              //顯示圖形
              img.Save(Response.OutputStream, ImageFormat.Jpeg);;
              g.Dispose();
              Response.Write("<br>" + MyDc.intData.ToString());
          }



        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約