0

我希望使用 microsoft Visual Studio 2010 创建一个图表,但我不知道该怎么做。尝试用谷歌搜索答案,但没有一个是 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();
        }
    }

我想我被困在表示层有什么帮助吗?酒吧看起来像这样

4

1 回答 1

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(); 

更多阅读资源

我认为这是一个很好的例子,你可以通过这个链接
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

于 2012-12-25T07:14:41.020 回答