• MSChart使用 对图形样式的部分设置,一般对series设置


    使用雷达图样式:System.Web.UI.DataVisualization.Charting.SeriesChartType.Radar

    /// <summary>
        /// 绑定显示数据webform
        /// </summary>
        /// <param name="chart">要绑定数据chart</param>
        /// <param name="dt">要绑定的数据表</param>
        /// <param name="XCol">图标X轴的列名</param>
        /// <param name="YCols">图表Y轴的列名集合,用|分隔</param>
        /// <param name="sTitle">图表的标题</param>
        /// <param name="chartType">图表的显示类型</param>
        /// <param name="IsStaggered">是否错位显示列</param>
        public static void ShowBindForPointAndWebForm(System.Web.UI.DataVisualization.Charting.Chart chart, DataTable dt, string XCol, string YCols, string sTitle, System.Web.UI.DataVisualization.Charting.SeriesChartType chartType, bool IsStaggered)
        {
            if (dt == null)
            {
                return;
            }
            string[] col = YCols.Split('|');
            chart.Series.Clear();

            //刻度最大、最小、当前值
            double max = 0;
            double min = 0;
            double cut = 0;

            for (int i = 0; i < col.Length; i++)
            {//一个series代表一个数据列
                System.Web.UI.DataVisualization.Charting.Series series = new System.Web.UI.DataVisualization.Charting.Series();

                series.BorderWidth = 3;
                series.Name = col[i].ToString();
                series.ChartType = chartType;
                series.Points.Clear();

                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    cut = double.Parse(dt.Rows[j][col[i].ToString()].ToString());

                    //计算刻度最大、最小、当前值
                    if (i == 0 && j == 0)
                    {
                        max = cut;
                        min = cut;
                    }
                    if (cut > max)
                    {
                        max = cut;
                    }
                    if (cut < min)
                    {
                        min = cut;
                    }

                    series.Points.AddXY(dt.Rows[j][XCol].ToString() +" "+ string.Format("{0:C0}", cut) +"(元)", cut);//设置的point的位置,不是实体数值
                    series.Points[series.Points.Count - 1].IsVisibleInLegend = true;
                   
                    if (i==0)
                    {//是否每个数据列都显示数据值标签
                        series.Points[series.Points.Count - 1].Label = cut.ToString();//date[i].ToString();
                    }
                    else
                    {
                        series.Points[series.Points.Count - 1].Label = "";
                    }

                    series.Points[series.Points.Count - 1].LegendText = dt.Rows[j][XCol].ToString();

                    series.Points[series.Points.Count - 1].ToolTip = dt.Rows[j][XCol].ToString() + "" + string.Format("{0:C0}", cut) + "(元)";
                }


                series.CustomProperties = "DrawingStyle=Cylinder";//柱图为圆形,图形的样式
                series["RadarDrawingStyle"] = "Line";//雷达图中的图形样式为折线图(默认是区域图)
                series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;//图形中的各个数据点样式显示(默认是没有的),可以修改设置为:方块、三角等样式

                chart.Series.Add(series);
            }
            chart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;//Y轴刻度线数据值不显示
            chart.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;//Y轴刻度线不显示
            if (max != 0)
            {//判定Y轴数据范围
                int MaxLength = Convert.ToInt32(max).ToString().Length;
                double MaxChu = Math.Pow(10, MaxLength - 2);

                chart.ChartAreas[0].AxisY.Interval = Math.Ceiling(max / MaxChu) * (MaxChu / 10);
                chart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(max / MaxChu) * MaxChu;
                chart.ChartAreas[0].AxisY.Minimum = 0;
            }

            chart.ChartAreas[0].AxisX.Maximum = dt.Rows.Count + 1;   //设置X轴最大坐标值
            chart.ChartAreas[0].AxisX.Minimum = 0;   //设置X轴最大坐标值

            if (chart.Titles.Count != 0)
            {//添加图形标题
                chart.Titles[0].Text = sTitle;
            }
            else
            {
                chart.Titles.Add("title1");
                chart.Titles[0].Text = sTitle;
            }
            if (IsStaggered)
            {
                //解决X轴多长则不显示的问题
                chart.ChartAreas[0].AxisX.Interval = 1;   //设置X轴坐标的间隔为1
                chart.ChartAreas[0].AxisX.IntervalOffset = 1;  //设置X轴坐标偏移为1
                chart.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;   //设置是否交错显示,比如数据多的时间分成两行来显示
            }
        }

    结果:

  • 相关阅读:
    Cocos Creator Editor 第一个编辑器扩展(扩展菜单)
    Rider 设置
    unity 使用GameObject.SetActive(true)激活对象时,会在SetActive内部调用Awake和OnEnable函数
    unity/C# 结构体属性使用set和get访问器应注意的问题
    unity 自定义AssetImporter导入指定资源
    Duilib部分源码解析
    TreeView树形控件的使用
    JQuery 文档资源收集
    排序和搜索(一)插入排序系列
    字符相关类型和编码概念
  • 原文地址:https://www.cnblogs.com/jiutianxingchen/p/2958997.html
Copyright © 2020-2023  润新知