参考链接:https://blog.csdn.net/qq_38628970/article/details/91041879
柱状图
string[] x = new string[] { "南山大队", "福田大队", "罗湖大队", "宝安大队", "指挥处", };
double[] y = new double[] { 541, 574, 345, 854, 257 };
#region 柱状图
cht1.Titles.Add("柱状图数据分析");
cht1.Titles[0].ForeColor = Color.Black;
cht1.Titles[0].Font = new Font("宋体", 5f, FontStyle.Regular);
cht1.Titles[0].Alignment = ContentAlignment.TopCenter;
cht1.Titles.Add("合计:0 宗");
cht1.Titles[1].ForeColor = Color.Black;
cht1.Titles[1].Font = new Font("宋体", 5f, FontStyle.Regular);
cht1.BackColor = Color.Yellow;
cht1.ChartAreas[0].BackColor = Color.Transparent;
cht1.ChartAreas[0].BorderColor = Color.Transparent;
cht1.ChartAreas[0].AxisX.Interval = 1;
cht1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht1.ChartAreas[0].AxisX.TitleFont = new Font("宋体", 5f, FontStyle.Regular);
cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht1.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
cht1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("宋体", 5f, FontStyle.Regular);
cht1.ChartAreas[0].AxisX.Title = "数量(个)";
cht1.ChartAreas[0].AxisX.TitleFont = new Font("宋体", 5f, FontStyle.Regular);
cht1.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht1.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;
cht1.ChartAreas[0].AxisX.ToolTip = "数量(个)";
cht1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht1.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht1.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
cht1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("宋体", 5f, FontStyle.Regular);
cht1.ChartAreas[0].AxisY.Title = "数量(个)";
cht1.ChartAreas[0].AxisY.TitleFont = new Font("宋体", 5f, FontStyle.Regular);
cht1.ChartAreas[0].AxisY.TitleForeColor = Color.Black;
cht1.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
cht1.ChartAreas[0].AxisY.ToolTip = "数量(个)";
cht1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht1.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht1.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht1.ChartAreas[0].BackGradientStyle = GradientStyle.TopBottom;
string now_time = System.DateTime.Now.ToString("d");
Legend legend = new Legend(now_time);
legend.Title = "legendTitle";
cht1.Series[0].XValueType = ChartValueType.String;
cht1.Series[0].Label = "#VAL";
cht1.Series[0].LabelForeColor = Color.Black;
cht1.Series[0].ToolTip = "#VALX:#VAL";
cht1.Series[0].ChartType = SeriesChartType.Column;
cht1.Series[0].Color = Color.Lime;
cht1.Series[0].LegendText = legend.Name;
cht1.Series[0].IsValueShownAsLabel = true;
cht1.Series[0].LabelForeColor = Color.Black;
cht1.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht1.Legends.Add(legend);
cht1.Legends[0].Position.Auto = false;
cht1.Series[0].Points.DataBindXY(x, y);
cht1.Series[0].Points[0].Color = Color.Black;
cht1.Series[0].Palette = ChartColorPalette.Bright;
#endregion
饼图
#region 饼图
cht2.Titles.Add("饼图数据分析");
cht2.Titles[0].ForeColor = Color.Black;
cht2.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);
cht2.Titles[0].Alignment = ContentAlignment.TopCenter;
cht2.Titles.Add("合计:25412 宗");
cht2.Titles[1].ForeColor = Color.Black;
cht2.Titles[1].Font = new Font("微软雅黑", 8f, FontStyle.Regular);
cht2.Titles[1].Alignment = ContentAlignment.TopRight;
cht2.BackColor = Color.Transparent;
cht2.ChartAreas[0].BackColor = Color.Transparent;
cht2.ChartAreas[0].BorderColor = Color.Transparent;
cht2.ChartAreas[0].AxisX.Interval = 1;
cht2.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht2.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht2.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);
cht2.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht2.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht2.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
cht2.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisX.Title = "数量(宗)";
cht2.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht2.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;
cht2.ChartAreas[0].AxisX.ToolTip = "数量(宗)";
cht2.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht2.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht2.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht2.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
cht2.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisY.Title = "数量(宗)";
cht2.ChartAreas[0].AxisY.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisY.TitleForeColor = Color.Black;
cht2.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
cht2.ChartAreas[0].AxisY.ToolTip = "数量(宗)";
cht2.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht2.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht2.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht2.ChartAreas[0].BackGradientStyle = GradientStyle.None;
Legend legend2 = new Legend("#VALX");
legend2.Title = "图例";
legend2.TitleBackColor = Color.Transparent;
legend2.BackColor = Color.Transparent;
legend2.TitleForeColor = Color.Black;
legend2.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
legend2.Font = new Font("微软雅黑", 8f, FontStyle.Regular);
legend2.ForeColor = Color.Black;
cht2.Series[0].XValueType = ChartValueType.String;
cht2.Series[0].Label = "#VAL";
cht2.Series[0].LabelForeColor = Color.Black;
cht2.Series[0].ToolTip = "#VALX:#VAL(宗)";
cht2.Series[0].ChartType = SeriesChartType.Pie;
cht2.Series[0].Color = Color.Lime;
cht2.Series[0].LegendText = legend2.Name;
cht2.Series[0].IsValueShownAsLabel = true;
cht2.Series[0].LabelForeColor = Color.Black;
cht2.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht2.Series[0].CustomProperties = "PieLabelStyle = Outside";
cht2.Legends[0].Position.Auto = true;
cht2.Series[0].IsValueShownAsLabel = true;
cht2.Series[0].IsVisibleInLegend = true;
cht2.Series[0].ShadowOffset = 0;
cht2.Series[0]["PieLineColor"] = "White";
cht2.Series[0].Points.DataBindXY(x, y);
cht2.Series[0].Points[0].Color = Color.Black;
cht2.Series[0].Palette = ChartColorPalette.BrightPastel;
#endregion
横向柱状图
#region Bar图
cht3.Titles.Add("交通违法行为TOP5");
cht3.Titles[0].ForeColor = Color.Black;
cht3.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);
cht3.Titles[0].Alignment = ContentAlignment.TopCenter;
cht3.Titles.Add("合计:25412 宗 ");
cht3.Titles[1].ForeColor = Color.Black;
cht3.Titles[1].Font = new Font("微软雅黑", 8f, FontStyle.Regular);
cht3.Titles[1].Alignment = ContentAlignment.TopRight;
cht3.BackColor = Color.Transparent;
cht3.ChartAreas[0].BackColor = Color.Transparent;
cht3.ChartAreas[0].BorderColor = Color.Transparent;
cht3.ChartAreas[0].AxisX.Interval = 1;
cht3.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht3.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht3.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);
cht3.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht3.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht3.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
cht3.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht3.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht3.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht3.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht3.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
cht3.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht3.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht3.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht3.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht3.ChartAreas[0].AxisX.IsMarginVisible = false;
cht3.ChartAreas[0].Area3DStyle.Enable3D = true;
cht2.ChartAreas[0].BackGradientStyle = GradientStyle.None;
Legend legend3 = new Legend("#VALX");
legend3.Title = "图例";
legend3.TitleBackColor = Color.Transparent;
legend3.BackColor = Color.Transparent;
legend3.TitleForeColor = Color.Black;
legend3.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
legend3.Font = new Font("微软雅黑", 8f, FontStyle.Regular);
legend3.ForeColor = Color.Black;
cht3.Series[0].XValueType = ChartValueType.String;
cht3.Series[0].Label = "#VAL";
cht3.Series[0].LabelForeColor = Color.Black;
cht3.Series[0].ToolTip = "#VALX:#VAL(宗)";
cht3.Series[0].ChartType = SeriesChartType.Bar;
cht3.Series[0].Color = Color.Lime;
cht3.Series[0].IsValueShownAsLabel = true;
cht3.Series[0].LabelForeColor = Color.Black;
cht3.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht3.Series[0].CustomProperties = "PieLabelStyle = Outside";
cht3.Series[0].IsVisibleInLegend = true;
cht3.Series[0].ShadowOffset = 0;
cht3.Series[0]["PieLineColor"] = "White";
cht3.Series[0].Points.DataBindXY(x, y);
cht3.Series[0].Palette = ChartColorPalette.BrightPastel;
#endregion
雷达图
cht4.Titles.Add("交通违法行为TOP5");
cht4.Titles[0].ForeColor = Color.Black;
cht4.Titles[0].Font = new Font("微软雅黑", 12f, FontStyle.Regular);
cht4.Titles[0].Alignment = ContentAlignment.TopCenter;
cht4.Titles.Add("合计:25412 宗 ");
cht4.Titles[1].ForeColor = Color.Black;
cht4.Titles[1].Font = new Font("微软雅黑", 8f, FontStyle.Regular);
cht4.Titles[1].Alignment = ContentAlignment.TopRight;
cht4.BackColor = Color.Transparent;
cht4.ChartAreas[0].BackColor = Color.Transparent;
cht4.ChartAreas[0].BorderColor = Color.Transparent;
cht4.ChartAreas[0].AxisX.Interval = 1;
cht4.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht4.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht4.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 14f, FontStyle.Regular);
cht4.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
cht4.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht4.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
cht4.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht4.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht4.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht4.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht4.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
cht4.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 10f, FontStyle.Regular);
cht4.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht4.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht4.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht4.ChartAreas[0].AxisX.IsMarginVisible = false;
cht4.ChartAreas[0].Area3DStyle.Enable3D = true;
cht4.ChartAreas[0].AxisX.IsInterlaced = false;
cht4.ChartAreas[0].AxisX.IsMarginVisible = false;
cht4.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
cht4.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
cht4.ChartAreas[0].BackGradientStyle = GradientStyle.None;
Legend legend4 = new Legend();
legend4.Title = "图例";
legend4.TitleBackColor = Color.Transparent;
legend4.BackColor = Color.Transparent;
legend4.TitleForeColor = Color.Black;
legend4.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
legend4.Font = new Font("微软雅黑", 8f, FontStyle.Regular);
legend4.ForeColor = Color.Black;
cht4.Legends.Add(legend4);
cht4.Legends[0].Position.Auto = true;
cht4.Series[0].XValueType = ChartValueType.String;
cht4.Series[0].Label = "#VAL";
cht4.Series[0].LabelForeColor = Color.Black;
cht4.Series[0].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[0].ChartType = SeriesChartType.Radar;
cht4.Series[0]["RadarDrawingStyle"] = "Line";
cht4.Series[0].LegendText = "2015年";
cht4.Series[0].IsValueShownAsLabel = true;
cht4.Series.Add(new Series("Series2"));
cht4.Series[1].Label = "#VAL";
cht4.Series[1].LabelForeColor = Color.Black;
cht4.Series[1].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[1].ChartType = SeriesChartType.Radar;
cht4.Series[1]["RadarDrawingStyle"] = "Line";
cht4.Series[1].LegendText = "2016年";
cht4.Series[1].IsValueShownAsLabel = true;
cht4.Series.Add(new Series("Series3"));
cht4.Series[2].Label = "#VAL";
cht4.Series[2].LabelForeColor = Color.Black;
cht4.Series[2].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[2].ChartType = SeriesChartType.Radar;
cht4.Series[2]["RadarDrawingStyle"] = "Line";
cht4.Series[2].LegendText = "2017年";
cht4.Series[2].IsValueShownAsLabel = true;
double[] yValues = { 65.62, 75.54, 60.45, 34.73, 85.42, 55.9, 63.6, 55.2, 77.1 };
string[] xValues = { "France", "Canada", "Germany", "USA", "Italy", "Spain", "Russia", "Sweden", "Japan" };
double[] y2 = { 45.62, 65.54, 70.45, 84.73, 35.42, 55.9, 63.6 };
double[] y3 = { 88.62, 35.54, 52.45, 45.73, 88.42, 14.9, 33.6 };
this.cht4.Series[0].Points.DataBindXY(xValues, yValues);
this.cht4.Series[1].Points.DataBindY(y2);
this.cht4.Series[2].Points.DataBindY(y3);
cht4.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
cht4.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Near;
for (int i = 0; i < cht4.Series[2].Points.Count; i++)
{
cht4.Series[2].Points[i].MarkerStyle = MarkerStyle.Circle;
cht4.Series[2].Points[i].MarkerColor = Color.Red;
}
for (int i = 0; i < cht4.Series.Count; i++)
{
for (int j = 0; j < cht4.Series[i].Points.Count; j++)
{
cht4.Series[i].Points[j].Label = " ";
}
}
cht4.AntiAliasing = AntiAliasingStyles.All;
cht4.Palette = ChartColorPalette.BrightPastel;
cht4.Series[0].ChartType = SeriesChartType.Radar;
cht4.Series[1].ChartType = SeriesChartType.Radar;
cht4.Series[2].ChartType = SeriesChartType.Radar;
cht4.Width = 500;
cht4.Height = 350;
}