Chart控件,把Y轴设置成百分比

时间:2021-10-10 14:54:40

Chart控件,把Y轴设置成百分比

这次所有属性设置都用代码(就当整理便于以后查询)。
在窗体放置一个Chart控件,未做任何设置;然后编写代码:

//设置
chart2.Legends[

].Enabled = false;//不显示图例


chart2.ChartAreas[

].BackColor = Color.White;//设置背景为白色


chart2.ChartAreas[

].Area3DStyle.Enable3D = true;//设置3D效果

chart2.ChartAreas[

].Area3DStyle.PointDepth =
chart2.ChartAreas[].Area3DStyle.PointGapDepth = ;//设置一下深度,看起来舒服点……

chart2.ChartAreas[

].Area3DStyle.WallWidth = ;//设置墙的宽度为0;


chart2.ChartAreas[

].AxisY.LabelStyle.Format = "0%";//格式化,为了显示百分号

chart2.ChartAreas[

].AxisY.Interval = 0.05;//设置刻度间隔为5%

chart2.ChartAreas[

].AxisX.MajorGrid.Enabled =
chart2.ChartAreas[].AxisY.MajorGrid.Enabled = false;//不显示网格线


chart2.ChartAreas[

].AxisX.Minimum = 0.5;//设置最小值,为了让第一个柱紧挨坐标轴


chart2.Series[

].Label = "#VAL{P}";//设置标签文本 (在设计期通过属性窗口编辑更直观)

chart2.Series[

].IsValueShownAsLabel = true;//显示标签


chart2.Series[

].CustomProperties = "DrawingStyle=Cylinder, PointWidth=1";//设置为圆柱形 (在设计期通过属性窗口编辑更直观)

chart2.Series[

].Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel;//设置调色板

//数据

chart2.Series[

].Points.AddXY("<10",0.201);
chart2.Series[].Points.AddXY("10~20", 0.395);
chart2.Series[].Points.AddXY("20~30", 0.173);
chart2.Series[].Points.AddXY("30~40", 0.136);
chart2.Series[].Points.AddXY("40~50", 0.059);
chart2.Series[].Points.AddXY("50~60", 0.015);
chart2.Series[].Points.AddXY(">60", 0.022

);