• C# Chart各个属性详细解析、应用


    Chart笔记

    前台页面代码:

    <form id="form1" runat="server">

        <div>

        

            <asp:Chart ID="Chart1" runat="server">

                <Series>

                    <asp:Series Name="Series1">

                    </asp:Series>

                     <asp:Series Name="Series2">

                    </asp:Series>

                </Series>

                <ChartAreas>

                    <asp:ChartArea Name="ChartArea1">

                    </asp:ChartArea>

                </ChartAreas>

            </asp:Chart>

        

        </div>

    </form>

    后台代码以及属性的解释:

            static string sqlconn = "Data Source=.;Initial Catalog=XTest;Integrated Security=True";

            protected void Page_Load(object sender, EventArgs e)

            {

                xxw x = getData();

                Chart1.DataSource = getlist();

                #region 图表样式

                Chart1.BackGradientStyle= = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;//指定图表元素的渐变样式(中心向外,从左到右,从上到下等等)

                Chart1.BackSecondaryColor = System.Drawing.Color.Yellow;//设置背景的辅助颜色

                Chart1.BorderlineColor = System.Drawing.Color.Yellow;//设置图像边框的颜色

                Chart1.BorderlineDashStyle=  System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;//设置图像边框线的样式(实线、虚线、点线)

                Chart1.BorderlineWidth = 2;//设置图像的边框宽度

                Chart1.BorderSkin.SkinStyle=  System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;//设置图像的边框外观样式

                Chart1.BackColor = System.Drawing.Color.Yellow;//设置图表的背景颜色

                #endregion

                #region 数据样式

                Chart1.Series["Series1"].XValueMember = "name";//设置X轴的数据源

                Chart1.Series["Series1"].YValueMembers = "mobile";//设置Y轴的数据源

                Chart1.Series["Series2"].XValueMember = "name";

                Chart1.Series["Series2"].YValueMembers = "id";

                Chart1.Series["Series2"].Color = System.Drawing.Color.Red;//设置颜色

                Chart1.Series["Series2"].ChartType= System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;//设置图表的类型(饼状、线状等等)

                Chart1.Series["Series1"].IsValueShownAsLabel = true;//设置是否在Chart中显示坐标点值

                Chart1.Series["Series1"].BorderColor = System.Drawing.Color.Red;//设置数据边框的颜色

                Chart1.BackColor = System.Drawing.Color.Red;//设置图表的背景颜色

                Chart1.Series["Series1"].Color = System.Drawing.Color.Black;//设置数据的颜色

                Chart1.Series["Series1"].Name = "数据1";//设置数据名称

                Chart1.Series["数据1"].ShadowOffset = 1;//设置阴影偏移量

                Chart1.Series["数据1"].ShadowColor = System.Drawing.Color.PaleGreen;//设置阴影颜色

                #endregion

                #region 图表区域样式

                Chart1.ChartAreas["ChartArea1"].Name = "图表区域";

                Chart1.ChartAreas["图表区域"].Position.Auto = true;//设置是否自动设置合适的图表元素

                Chart1.ChartAreas["图表区域"].ShadowColor = System.Drawing.Color.YellowGreen;//设置图表的阴影颜色

                Chart1.ChartAreas["图表区域"].Position.X=5.089137F;//设置图表元素左上角对应的X坐标

                Chart1.ChartAreas["图表区域"].Position.Y = 5.895753F;//设置图表元素左上角对应的Y坐标

                Chart1.ChartAreas["图表区域"].Position.Height = 86.76062F;//设置图表元素的高度

                Chart1.ChartAreas["图表区域"].Position.Width = 88F;//设置图表元素的宽度

                Chart1.ChartAreas["图表区域"].InnerPlotPosition.Auto = false;//设置是否在内部绘图区域中自动设置合适的图表元素

                Chart1.ChartAreas["图表区域"].InnerPlotPosition.Height = 85F;//设置图表元素内部绘图区域的高度

                Chart1.ChartAreas["图表区域"].InnerPlotPosition.Width = 86F;//设置图表元素内部绘图区域的宽度

                Chart1.ChartAreas["图表区域"].InnerPlotPosition.X = 8.3969F;//设置图表元素内部绘图区域左上角对应的X坐标

                Chart1.ChartAreas["图表区域"].InnerPlotPosition.Y = 3.63068F;//设置图表元素内部绘图区域左上角对应的Y坐标

                Chart1.ChartAreas["图表区域"].Area3DStyle.Inclination = 10;//设置三维图表的旋转角度

                Chart1.ChartAreas["图表区域"].Area3DStyle.IsClustered = true;//设置条形图或柱形图的的数据系列是否为簇状

                Chart1.ChartAreas["图表区域"].Area3DStyle.IsRightAngleAxes = true;//设置图表区域是否使用等角投影显示

                Chart1.ChartAreas["图表区域"].Area3DStyle.LightStyle = System.Web.UI.DataVisualization.Charting.LightStyle.Realistic;//设置图表的照明类型(色调随旋转角度改变而改变,不应用照明,色调不改变)

                Chart1.ChartAreas["图表区域"].Area3DStyle.Perspective = 50;//设置三维图区的透视百分比

                Chart1.ChartAreas["图表区域"].Area3DStyle.Rotation = 60;//设置三维图表区域绕垂直轴旋转的角度

                Chart1.ChartAreas["图表区域"].Area3DStyle.WallWidth = 0;//设置三维图区中显示的墙的宽度

                Chart1.ChartAreas["图表区域"].Area3DStyle.Enable3D = true;//设置是否显示3D效果

                Chart1.ChartAreas["图表区域"].BackColor = System.Drawing.Color.Green;//设置图表区域的背景颜色

                Chart1.ChartAreas["图表区域"].BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.LeftRight;//指定图表元素的渐变样式(中心向外,从左到右,从上到下等等)

                Chart1.ChartAreas["图表区域"].BackSecondaryColor = System.Drawing.Color.White;//设置图表区域的辅助颜色

                Chart1.ChartAreas["图表区域"].BorderColor = System.Drawing.Color.White;//设置图表区域边框颜色

                Chart1.ChartAreas["图表区域"].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;//设置图像边框线的样式(实线、虚线、点线)

                Chart1.ChartAreas["图表区域"].AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);//设置X轴下方的提示信息的字体属性

                Chart1.ChartAreas["图表区域"].AxisX.LabelStyle.Format = "";//设置标签文本中的格式字符串

                Chart1.ChartAreas["图表区域"].AxisX.LabelStyle.Interval=5D;//设置标签间隔的大小

                Chart1.ChartAreas["图表区域"].AxisX.LabelStyle.IntervalType = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;//设置间隔大小的度量单位

                Chart1.ChartAreas["图表区域"].AxisX.LineColor = System.Drawing.Color.White;//设置X轴的线条颜色

                Chart1.ChartAreas["图表区域"].AxisX.MajorGrid.Interval=5D;//设置主网格线与次要网格线的间隔

                Chart1.ChartAreas["图表区域"].AxisX.MajorGrid.IntervalType = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;//设置主网格线与次网格线的间隔的度量单位

                Chart1.ChartAreas["图表区域"].AxisX.MajorGrid.LineColor = System.Drawing.Color.Snow;//设置网格线的颜色

                Chart1.ChartAreas["图表区域"].AxisX.MajorTickMark.Interval = 5D;//设置刻度线的间隔

                Chart1.ChartAreas["图表区域"].AxisX.MajorTickMark.IntervalType = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;//设置刻度线的间隔的度量单位

                Chart1.ChartAreas["图表区域"].AxisY.IsLabelAutoFit = false;//设置是否自动调整轴标签

                Chart1.ChartAreas["图表区域"].AxisY.IsStartedFromZero = false;//设置是否自动将数据值均为正值时轴的最小值设置为0,存在负数据值时,将使用数据轴最小值

                Chart1.ChartAreas["图表区域"].AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);//设置Y轴左侧的提示信息的字体属性

                Chart1.ChartAreas["图表区域"].AxisY.LineColor = System.Drawing.Color.DarkBlue;//设置轴的线条颜色

                Chart1.ChartAreas["图表区域"].AxisY.MajorGrid.LineColor = System.Drawing.Color.White;//设置网格线颜色

                Chart1.ChartAreas["图表区域"].AxisY.Maximum = getmax() + 100;//设置Y轴最大值

                Chart1.ChartAreas["图表区域"].AxisY.Minimum=0;//设置Y轴最小值

                #endregion

                #region 图例样式

                Legend l = new Legend();//初始化一个图例的实例

                l.Alignment = System.Drawing.StringAlignment.Near;//设置图表的对齐方式(中间对齐,靠近原点对齐,远离原点对齐)

                l.BackColor = System.Drawing.Color.Black;//设置图例的背景颜色

                l.DockedToChartArea = "ChartArea1";//设置图例要停靠在哪个区域上

                l.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom;//设置停靠在图表区域的位置(底部、顶部、左侧、右侧)

                l.Font =new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);//设置图例的字体属性

                l.IsTextAutoFit = true;//设置图例文本是否可以自动调节大小

                l.LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Column;//设置显示图例项方式(多列一行、一列多行、多列多行)

                l.Name = "l1";//设置图例的名称

                Chart1.Legends.Add(l.Name);

                #endregion

            }

            #region 数据

            public xxw getData()

            {

                using (SqlConnection conn = new SqlConnection(sqlconn))

                {

                    conn.Open();

                    string sql = "select * from xxw";

                    SqlCommand comm = conn.CreateCommand();

                    comm.CommandText = sql;

                    SqlDataReader r = comm.ExecuteReader();

                    if (r.HasRows)

                    {

                        r.Read();

                        xxw x = new xxw();

                        x.Id = Convert.ToInt32(r["id"]);

                        x.Name = r["name"].ToString();

                        x.Sex = r["sex"].ToString();

                        x.Address = r["address"].ToString();

                        x.Mobile = Convert.ToInt32(r["mobile"]);

                        x.Intro = r["intro"].ToString();

                        return x;

                    }

                    else

                    {

                        return null;

                    }

                }

            }

            public DataSet getlist()

            {

                using (SqlConnection conn = new SqlConnection(sqlconn))

                {

                    conn.Open();

                    string sql = "select * from xxw";

                    SqlCommand comm = conn.CreateCommand();

                    comm.CommandText = sql;

                    SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

                    DataSet ds = new DataSet();

                    adapter.Fill(ds);

                    return ds;

                }

            }

            public int getmax()

            {

                using (SqlConnection conn = new SqlConnection(sqlconn))

                {

                    conn.Open();

                    string sql = "select Max(mobile) from xxw";

                    SqlCommand comm = conn.CreateCommand();

                    comm.CommandText = sql;

                    int max = Convert.ToInt32(comm.ExecuteScalar());

                    return max;

                }

            }

            #endregion

  • 相关阅读:
    jQuery图片切换插件jquery.cycle.js
    UVA
    FragmentPagerAdapter和FragmentStatePagerAdapter的差别
    更改jdk所用内存空间
    一次性能优化将filter转换
    JSP中文件的上传于下载演示样例
    Diskpart工具应用两则:MBR/GPT分区转换 &amp; 基本/动态磁盘转换
    LDD3之并发和竞态-completion(完毕量)的学习和验证
    二维码的扫描、生成
    输入一行字符,分别统计出包括英文字母、空格、数字和其他字符的个数
  • 原文地址:https://www.cnblogs.com/cyh328863397/p/7470816.html
Copyright © 2020-2023  润新知