![](https://i-blog.csdnimg.cn/blog_migrate/73af783b9155e20f3c16a9513bff0b40.png)
public Form1()
{
InitializeComponent();
Column(chart, x.ToArray(), y.ToArray());
}
public static void Column(Chart chart, string[] x, double[] y)
{
#region 柱状图
//标题
chart.Titles.Add(Form1.m_TableName1);
chart.Titles[0].ForeColor = Color.White;
chart.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);
chart.Titles[0].Alignment = ContentAlignment.TopCenter;
//控件背景
chart.BackColor = Color.Transparent;
//图表区背景
chart.ChartAreas[0].BackColor = Color.Transparent;
chart.ChartAreas[0].BorderColor = Color.Transparent;
//X轴标签间距
chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisX.LabelStyle.IsStaggered = false;
chart.ChartAreas[0].AxisX.LabelStyle.Angle = 45;
chart.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);
chart.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//X坐标轴颜色
chart.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
//X坐标轴标题
//chart.ChartAreas[0].AxisX.Title = "部门";
chart.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
chart.ChartAreas[0].AxisX.TitleForeColor = Color.White;
chart.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;
chart.ChartAreas[0].AxisX.ToolTip = "部门";
//X轴网络线条
chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//Y坐标轴颜色
chart.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
chart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
chart.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
//Y坐标轴标题
//chart.ChartAreas[0].AxisY.Title = "数量(次)";
chart.ChartAreas[0].AxisY.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
chart.ChartAreas[0].AxisY.TitleForeColor = Color.White;
chart.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
chart.ChartAreas[0].AxisY.ToolTip = "数量(次)";
//Y轴网格线条
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//背景渐变
chart.ChartAreas[0].BackGradientStyle = GradientStyle.None;
chart.ChartAreas[0].Area3DStyle.Enable3D = true;
chart.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
//chart.ChartAreas[0].BackGradientStyle = GradientStyle.TopBottom;
Legend legend = new Legend("legend");
legend.Title = "legendTitle";
chart.Series[0].XValueType = ChartValueType.String; //设置X轴上的值类型
chart.Series[0].Label = "#VAL"; //设置显示X Y的值
chart.Series[0].LabelForeColor = Color.White;
chart.Series[0].ToolTip = "#VALX:#VAL"; //鼠标移动到对应点显示数值
chart.Series[0].ChartType = SeriesChartType.Column; //图类型(折线)
chart.Series[0].Color = Color.Lime;
chart.Series[0].LegendText = legend.Name;
chart.Series[0].IsValueShownAsLabel = true;
chart.Series[0].LabelForeColor = Color.White;
chart.Series[0].CustomProperties = "DrawingStyle = Cylinder";
chart.Legends.Add(legend);
chart.Legends[0].Position.Auto = false;
//绑定数据
chart.Series[0].Points.DataBindXY(x, y);
//chart.Series[0].Points[0].Color = Color.LightPink;
chart.Series[0].Palette = ChartColorPalette.Bright;
#endregion
}