C#应用6——chart数据显示(柱状图、饼图、横向柱状图、雷达图)

参考链接: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.Add("合计:25414 宗");
            //cht1.Titles.Add("合计:25414 宗");
            //cht1.Titles.Add("合计:25414 宗");
            cht1.Titles[1].ForeColor = Color.Black;
            cht1.Titles[1].Font = new Font("宋体", 5f, FontStyle.Regular);
            //设置标题位于右上角
            //cht1.Titles[1].Alignment = ContentAlignment.TopRight;
            //cht1.Titles[2].Alignment = ContentAlignment.TopRight;
            //cht1.Titles[3].Alignment = ContentAlignment.TopRight;
            //cht1.Titles[4].Alignment = ContentAlignment.TopRight;

            //控件背景
            cht1.BackColor = Color.Yellow;
            //图表区背景
            cht1.ChartAreas[0].BackColor = Color.Transparent;
            cht1.ChartAreas[0].BorderColor = Color.Transparent;
            //X轴标签间距
            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;

            //X坐标轴颜色
            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);
            //X坐标轴标题
            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 = "数量(个)";
            //X轴网络线条
            cht1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
            cht1.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");

            //Y坐标轴颜色
            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);
            //Y坐标轴标题
            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 = "数量(个)";
            //Y轴网格线条
            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;  //设置X轴上的值类型
            cht1.Series[0].Label = "#VAL";                //设置显示X Y的值    
            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;
            //X轴标签间距
            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;

            //X坐标轴颜色
            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);
            //X坐标轴标题
            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 = "数量(宗)";
            //X轴网络线条
            cht2.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
            cht2.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");

            //Y坐标轴颜色
            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);
            //Y坐标轴标题
            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 = "数量(宗)";
            //Y轴网格线条
            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;  //设置X轴上的值类型
            cht2.Series[0].Label = "#VAL";                //设置显示X Y的值    
            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.Add(legend2);
            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;
            //X轴标签间距
            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;

            //X坐标轴颜色
            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);
            //X坐标轴标题
            //cht3.ChartAreas[0].AxisX.Title = "数量(宗)";
            //cht3.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
            //cht3.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
            //cht3.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Auto;
            //cht3.ChartAreas[0].AxisX.ToolTip = "数量(宗)";
            //X轴网络线条
            cht3.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
            cht3.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");

            //Y坐标轴颜色
            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);
            //Y坐标轴标题
            //cht3.ChartAreas[0].AxisY.Title = "数量(宗)";
            //cht3.ChartAreas[0].AxisY.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
            //cht3.ChartAreas[0].AxisY.TitleForeColor = Color.Black;
            //cht3.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Auto;
            //cht3.ChartAreas[0].AxisY.ToolTip = "数量(宗)";
            //Y轴网格线条
            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;  //设置X轴上的值类型
            cht3.Series[0].Label = "#VAL";                //设置显示X Y的值    
            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].LegendText = legend3.Name;
            cht3.Series[0].IsValueShownAsLabel = true;
            cht3.Series[0].LabelForeColor = Color.Black;
            cht3.Series[0].CustomProperties = "DrawingStyle = Cylinder";
            cht3.Series[0].CustomProperties = "PieLabelStyle = Outside";
            //cht3.Legends.Add(legend3);
            //cht3.Legends[0].Position.Auto = true;

            //是否显示图例
            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].Points[0].Color = Color.Black;
            //绑定颜色
            cht3.Series[0].Palette = ChartColorPalette.BrightPastel;

            //for (int n = 0; n < x.Length; n++)
            //{
            //    int ptIdx = cht3.Series[0].Points.AddY(Convert.ToDouble(y[n]));
            //    DataPoint pt = this.cht3.Series[0].Points[ptIdx];
            //    pt.LegendText = x[n] + " " + "#PERCENT{P2}" + " [ " + "#VAL{D} 次" + " ]";//右边标签列显示的文字  
            //    pt.Label = x[n] + " " + "#PERCENT{P2}" + " [ " + "#VAL{D} 次" + " ]"; //圆饼外显示的信息 

            //    //  pt.LabelToolTip = "#PERCENT{P2}";  
            //    //pt.LabelBorderColor = Color.Red;//文字背景色   
            //}

            #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;
            //X轴标签间距
            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;

            //X坐标轴颜色
            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);
            //X坐标轴标题
            //cht4.ChartAreas[0].AxisX.Title = "数量(宗)";
            //cht4.ChartAreas[0].AxisX.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
            //cht4.ChartAreas[0].AxisX.TitleForeColor = Color.Black;
            //cht4.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Auto;
            //cht4.ChartAreas[0].AxisX.ToolTip = "数量(宗)";
            //X轴网络线条
            cht4.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
            cht4.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");

            //Y坐标轴颜色
            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);
            //Y坐标轴标题
            //cht4.ChartAreas[0].AxisY.Title = "数量(宗)";
            //cht4.ChartAreas[0].AxisY.TitleFont = new Font("微软雅黑", 10f, FontStyle.Regular);
            //cht4.ChartAreas[0].AxisY.TitleForeColor = Color.Black;
            //cht4.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Auto;
            //cht4.ChartAreas[0].AxisY.ToolTip = "数量(宗)";
            //Y轴网格线条
            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].AxisX.MajorGrid.Enabled = false;
            //cht4.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            //cht4.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
            cht4.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
            //背景渐变
            cht4.ChartAreas[0].BackGradientStyle = GradientStyle.None;
            //cht4.ChartAreas[0].AxisX2.InterlacedColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;
            //cht4.ChartAreas[0].BorderWidth = 0;
            //cht4.ChartAreas[0].BackSecondaryColor = Color.Red;
            //cht4.ChartAreas[0].BackImageTransparentColor = Color.Red;
            //cht4.ChartAreas[0].AxisX.InterlacedColor = Color.Red;
            //cht4.ChartAreas[0].AxisX.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisX2.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisX2.MajorGrid.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisX2.MajorTickMark.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisX2.MinorTickMark.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisY.InterlacedColor = Color.Red;
            //cht4.ChartAreas[0].AxisY.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.MajorGrid.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.MajorTickMark.LineColor = Color.Red;
            //cht4.ChartAreas[0].AxisY2.MinorTickMark.LineColor = Color.Red;


            //图例样式
            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;

            //Series1
            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;

            //Series2
            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;

            //Series3
            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" };


            //Seris2  
            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);


            //设置X轴显示间隔为1,X轴数据比较多的时候比较有用  
            cht4.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
            //设置XY轴标题的名称所在位置位远  
            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;//设置seires中折点的颜色   
            //    cht4.Series[1].Points[i].MarkerStyle = MarkerStyle.Square;//设置折点的风格     
            //    cht4.Series[1].Points[i].MarkerColor = Color.Blue;//设置seires中折点的颜色  
            //    cht4.Series[2].Points[i].MarkerStyle = MarkerStyle.Square;//设置折点的风格     
            //    cht4.Series[2].Points[i].MarkerColor = Color.Green;//设置seires中折点的颜色  
            }
            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.Series[i].Points[j].LabelToolTip = "string.Empty";
                }
            }
            //cht4.ImageType = ChartImageType.Jpeg;
            //反锯齿  
            cht4.AntiAliasing = AntiAliasingStyles.All;
            //调色板 磨沙:SemiTransparent  
            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;

            

            /* 
                 #VALX      显示当前图例的X轴的对应文本(或数据) 
                 #VAL, #VALY,  显示当前图例的Y轴的对应文本(或数据) 
                 #VALY2, #VALY3, 显示当前图例的辅助Y轴的对应文本(或数据) 
                 #SER:      显示当前图例的名称 
                 #LABEL       显示当前图例的标签文本 
                 #INDEX      显示当前图例的索引 
                 #PERCENT       显示当前图例的所占的百分比 
                 #TOTAL      总数量 
                 #LEGENDTEXT      图例文本 
                 */  
                    }
  • 12
    点赞
  • 124
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,下面是一个简单的例子,展示如何使用Python中的一些常用数据可视化库画出雷达、柱、词云和,并创建数据可视化大屏: 1. 雷达 ```python import matplotlib.pyplot as plt import numpy as np # 创建数据 categories = ['A', 'B', 'C', 'D', 'E'] values = [5, 3, 4, 2, 6] # 计算角度 angles = np.linspace(0, 2*np.pi, len(categories), endpoint=False) # 闭合形 values = np.concatenate((values, [values[0]])) angles = np.concatenate((angles, [angles[0]])) # 创建雷达 fig = plt.figure() ax = fig.add_subplot(111, polar=True) ax.plot(angles, values, 'o-', linewidth=2) ax.fill(angles, values, alpha=0.25) ax.set_thetagrids(angles * 180/np.pi, categories) ax.grid(True) # 显示像 plt.show() ``` 2. 柱 ```python import matplotlib.pyplot as plt # 创建数据 x = ['A', 'B', 'C', 'D', 'E'] y = [5, 3, 4, 2, 6] # 创建柱 fig, ax = plt.subplots() ax.bar(x, y) # 添加标签和标题 ax.set_xlabel('Categories') ax.set_ylabel('Values') ax.set_title('Example Bar Chart') # 显示像 plt.show() ``` 3. 词云 ```python from wordcloud import WordCloud import matplotlib.pyplot as plt # 创建词云 text = "Hello World! This is an example text for wordcloud." wordcloud = WordCloud().generate(text) # 显示词云 plt.imshow(wordcloud, interpolation='bilinear') plt.axis("off") plt.show() ``` 4. ```python import matplotlib.pyplot as plt # 创建数据 labels = ['A', 'B', 'C', 'D', 'E'] sizes = [5, 3, 4, 2, 6] # 创建 fig, ax = plt.subplots() ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90) # 添加标题 ax.set_title('Example Pie Chart') # 显示像 plt.show() ``` 5. 创建数据可视化大屏 一般来说,创建数据可视化大屏需要用到前端技术和可视化库,比如D3.js、Echarts等。这里提供一个简单的Python库dash,可以用Python代码创建交互式的数据可视化大屏。 ```python import dash import dash_core_components as dcc import dash_html_components as html # 创建app app = dash.Dash() # 创建布局 app.layout = html.Div(children=[ html.H1(children='Hello Dash'), html.Div(children=''' Dash: A web application framework for Python. '''), dcc.Graph( id='example-graph', figure={ 'data': [ {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'Category 1'}, {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'Category 2'}, ], 'layout': { 'title': 'Example Dash Plot' } } ) ]) # 启动app if __name__ == '__main__': app.run_server(debug=True) ``` 上面的代码创建了一个简单的Dash应用,包括一个标题、一个段落和一个柱。你可以根据需要修改这个例子,添加更多的组件和布局,创建你需要的数据可视化大屏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值