2012-12-25 30 views
0

我想創建一個圖表使用微軟的Visual Studio 2010,但我不知道該怎麼做。試圖回答,但沒有一個是3層。3層編程圖

這是我的數據訪問層

public List<AdvertisementDAL> displayChart() 
    { 
     List<AdvertisementDAL> dal = new List<AdvertisementDAL>(); 
     string sql = "Select * From AdvertisementRecord"; 
     SqlConnection conn = new SqlConnection(_connStr); 
     SqlCommand cmd = new SqlCommand(sql, conn); 
     conn.Open(); 
     SqlDataReader dr = cmd.ExecuteReader(); 
     while (dr.Read()) 
     { 
      _recordID = int.Parse(dr["RecordID"].ToString()); 
      _recordDate = dr["RecordDate"].ToString(); 
      _noOfClick = int.Parse(dr["NoOfClick"].ToString()); 
      _noOfView = int.Parse(dr["NoOfView"].ToString()); 
      _advertisementID = int.Parse(dr["FK_AdvertisementID"].ToString()); 
      dal.Add(new AdvertisementDAL(_recordID, _recordDate, _noOfClick, _noOfView, _advertisementID)); 
     } 
     conn.Close(); 
     dr.Close(); 
     dr.Dispose(); 
     return dal; 
    } 
} 

代碼這是我的業務邏輯層

public List<AdvertisementDAL> pieChart() 
    { 
     AdvertisementDAL dal = new AdvertisementDAL(); 
     List<AdvertisementDAL> dll = new List<AdvertisementDAL>(); 
     dll = dal.displayChart(); 
     return dll; 
    } 

這是我的表現層(我所知道的是數據綁定在一起)

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 

      AdvertisementBLL bll = new AdvertisementBLL(); 
      Chart1.DataSource = bll.pieChart(); 
      Chart1.DataBind(); 
     } 
    } 

我想我卡在表現層任何幫助嗎? 酒吧將是這個樣子

+0

您需要指定要在x軸和y軸上顯示的內容,屬性的名稱。 –

+0

在我的X軸上它將是編號1-100 在我的Y軸上它將是recordDate。 在條形圖上,它有兩個條形圖1是NoOfClick,另一個是noOfView – user1861753

回答

0

您可以使用這樣

// Set series members names for the X and Y values 
chart1.Series["Series 1"].XValueMember = "porpery1"; 
chart1.Series["Series 1"].YValueMembers = "property 2"; 
// Data bind to the selected data source 
chart1.DataBind(); 

更多閱讀source

我覺得這裏是一個很好的例子,你可以通過這個鏈接
http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
http://documentation.devexpress.com/#XtraCharts/CustomDocument7787
http://www.codeproject.com/Articles/117998/A-look-inside-the-ASP-NET-Charting-conlrol

+0

http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart -control.aspxhttp://documentation.devexpress.com/#XtraCharts/CustomDocument7787 該網站不存在 – user1861753

+0

嗨,我仍然不明白從codeproject.com一件事。 也許你可以幫我嗎? – user1861753