直接效果图
程序入口调用构造函数
public Form1()
{
InitializeComponent();
Bar(chart1, x.ToArray(), y.ToArray());
}
public static void Bar(Chart chart, string[] a,double[] b)
{
#region Bar图
//标题
chart.Titles.Add(Form1.m_TableName2);
chart.Titles[0].ForeColor = Color.White;
chart.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);
chart.Titles[0].Alignment = ContentAlignment.BottomCenter;
//控件背景
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 = true;
chart.ChartAreas[0].AxisX.LabelStyle.Angle = -5; //坐标字体角度
chart.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);
chart.ChartAreas[0].AxisX.TitleForeColor = Color.White;
chart.ChartAreas[0].AxisX.MaximumAutoSize = 20;
//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.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.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//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].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.Rotated270;
chart.ChartAreas[0].AxisX.ToolTip = "实验室";
chart.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
chart.ChartAreas[0].AxisX.IsMarginVisible = false;
chart.ChartAreas[0].Area3DStyle.Enable3D = true;
//背景渐变
chart.ChartAreas[0].BackGradientStyle = GradientStyle.None;
//是否显示图例
chart.Series[0].IsVisibleInLegend = false;
chart.Series[0].ShadowOffset = 0;
//图例样式
Legend legend3 = new Legend("#VALX");
legend3.Title = "图例";
legend3.TitleBackColor = Color.Transparent;
legend3.BackColor = Color.Transparent;
legend3.TitleForeColor = Color.Blue;
legend3.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
legend3.Font = new Font("微软雅黑", 8f, FontStyle.Regular);
legend3.ForeColor = Color.White;
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.Bar; //图类型(折线)
chart.Series[0].Color = Color.Lime;
//cht3.Series[0].LegendText = legend3.Name;
chart.Series[0].IsValueShownAsLabel = true;
chart.Series[0].LabelForeColor = Color.White;
chart.Series[0].CustomProperties = "DrawingStyle = Cylinder";
chart.Series[0].CustomProperties = "PieLabelStyle = Outside";
//绑定数据
chart.Series[0].Points.DataBindXY(a, b);
//绑定颜色
chart.Series[0].Palette = ChartColorPalette.BrightPastel;
#endregion
}