c# web Column chart(包含美观的样式)

1)前台代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication51.Default" %>


<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>



    


    

2)后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;


namespace WebApplication51
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindStudent();
            }
        }
        /// 
        /// 后台绑定
        /// 
        private void BindStudent()
        {
            List items = GetStudents();
            Series series = Chart1.Series[0];
            foreach (Student item in items)
            {
                DataPoint dataPoint = new DataPoint();
                dataPoint.SetValueXY(item.Name, item.Money);
                series.Points.Add(dataPoint);
            }
            Chart1.ChartAreas[0].AxisX.Title = "Student Name";
            Chart1.ChartAreas[0].AxisY.Title = "Money($)";
        }
        private List GetStudents()
        {
            List items = new List();
            items.Add(new Student("Chad", 1));
            items.Add(new Student("Catherine", 4));
            items.Add(new Student("Amamda", 3));
            items.Add(new Student("Emily", 2));
            return items;
        }
    }
    public class Student
    {
        public Student() { }
        public Student(string _name, decimal _money)
        {
            this.Name = _name;
            this.Money = _money;
        }
        public string Name { set; get; }
        public decimal Money { set; get; }
    }
}

3)错误解决方法

错误:Error executing child request for ChartImg.axd.

解决方法:在web.config 的节点小添加如下代码


             validate="false" />
   



你可能感兴趣的:(c#,web)