SunVoteChart - 副本.cs 51.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
/// ----------------------------------------------------------------
/// 文 件 名:ChartControl.cs
/// 功能描述:图表管理
/// 
/// 创建标识:Jdragon  2011-11-22
/// ----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using SunVoteARSPPT;


namespace GeneralLib
{
    /// <summary>
    /// 枚举类型(自定义枚举类型)
    /// </summary>
    public enum ChartTypes
    {
        /// <summary>
        /// 柱形图
        /// </summary>            
        ctColumn,
        /// <summary>
        /// 条形图
        /// </summary>
        ctBar,
        /// <summary>
        /// 垂直方块图 杨斌 2014-04-22      
        /// </summary>    
        ctColumnBox,
        /// <summary>
        /// 水平方块图 杨斌 2014-04-22
        /// </summary>
        ctBarBox,
        /// <summary>
        /// 饼图
        /// </summary>
        ctPie,
        /// <summary>
        /// 文本
        /// </summary>
        ctText,
    }

    /// <summary>
    /// 标签类型
    /// </summary>
    public enum LabelTypes
    {
        // 无标签
        ltNone,
        // 数值
        ltNumberValue,
        // 百分比
        ltPercent,
        // 数值加百分比
        ltNumberValueAndPercent,
    }

    /// <summary>
    /// 图例样式
    /// </summary>
    public enum LegendStyles
    {
        /// <summary>
        /// 列方式
        /// </summary>
        lsColumn = 0,
        /// <summary>
        /// 行方式
        /// </summary>
        lsRow = 1,
        /// <summary>
        /// 表格方式
        /// 杨斌 2014-02-25
        /// </summary>
        lstTable = 2
    }

    /// <summary>
    /// 图例对齐方式
    /// </summary>
    public enum LegentAlignments
    {
        /// <summary>
        /// 靠近布局对齐。在左到右布局中,近端位置是左。在右到左布局中,近端位置是右。
        /// </summary>
        laNear = 0,
        /// <summary>
        /// 居中对齐
        /// </summary>
        laCenter = 1,
        /// <summary>
        /// 指定文本远离布局矩形的原点位置对齐。在左到右布局中,远端位置是右。在右到左布局中,远端位置是左。
        /// </summary>
        laFar = 2
    }

    /// <summary>
    /// 图例位置
    /// </summary>
    public enum LegentDockings
    {
        /// <summary>
        /// 上
        /// </summary>
        ldTop = 0,
        /// <summary>
        /// 右
        /// </summary>
        ldRight = 1,
        /// <summary>
        /// 下
        /// </summary>
        ldBottom = 2,
        /// <summary>
        /// 左
        /// </summary>
        ldLeft = 3
    }

    public class ManageChart
    {
        /// <summary>
        /// 微软控件属性
        /// </summary>
        public Chart MsChart { get; set; }

        /// <summary>
        /// 图表类型(默认值:柱形图)
        /// </summary>
        private ChartTypes chartType = ChartTypes.ctColumn;
        /// <summary>
        /// 图表类型
        /// </summary>
        public ChartTypes ChartType
        {
            get
            {
                return chartType;
            }
            set
            {
                chartType = value;
            }
        }


        /// <summary>
        /// 图表宽度,默认为320
        /// </summary>
        private int width = 320;
        public int Width
        {
            get
            {
                return width <= 0 ? 320 : width;
            }
            set
            {
                if (value <= 0)
                    throw (new ApplicationException("Abnormal width of the chart, the width must be greater than 0"));
                width = (value <= 0) ? 320 : value;
            }
        }

        /// <summary>
        /// 图表高度,默认为240
        /// </summary>
        private int height = 240;
        public int Height
        {
            get
            {
                return height <= 0 ? 240 : height;
            }
            set
            {
                if (value <= 0)
                    throw (new ApplicationException("Degree of abnormal length of the chart, the width must be greater than 0"));
                height = (value <= 0) ? 240 : value;
            }
        }

        /// <summary>
        /// X轴值(选择项)
        /// </summary>
        public string[] XValue { get; set; }

        /// <summary>
        /// Y轴值集合
        /// </summary>
        public List<double[]> YValues { get; set; }


        /// <summary>
        /// 数据标签(默认值:数值)
        /// </summary>
        private LabelTypes labelType = LabelTypes.ltNumberValue;
        public LabelTypes LabelType
        {
            get
            {
                return labelType;
            }
            set
            {
                labelType = value;
            }
        }
        /// <summary>
        /// 2014-03-17 增加标签小数位数
        /// </summary>
        public int NumberDec = 0;
        public int PercentDec = 1;
        private double labelDenominator = 0;
        /// <summary>
        /// 百分比标签的分母,为0时表示以总数量计算,默认为0
        /// </summary>
        public double LabelDenominator
        {
            get
            {
                return labelDenominator;
            }
            set
            {
                if (value < 0)
                    throw (new ApplicationException("Percentage of the label must be greater than or equal to 0 denominator"));
                labelDenominator = value;
            }
        }

        /// <summary>
        /// 分母计算选项限制,如三键表决按赞成反对。默认0为所有选项。
        /// 杨斌 2015-06-18
        /// </summary>
        public int LabelDenominatorOptionLimit = 0;


        /// <summary>
        /// 计算系列总数值
        /// </summary>
        /// <param name="series">系列</param>
        /// <returns>总数值</returns>
        private int SumPointsValue(Series series)
        {
            int value = 0;

            //杨斌 2015-06-18
            int count = series.Points.Count;
            if ((this.LabelDenominatorOptionLimit > 0)
                && (this.LabelDenominatorOptionLimit < series.Points.Count))
            {
                count = this.LabelDenominatorOptionLimit;
            }
            for (int i = 0; i < count; i++)//杨斌 2015-06-18
            {
                value = value + (int)series.Points[i].GetValueByName("Y");
            }
            return value;
        }

        /// <summary>
        /// 杨斌 2012-06-29
        /// </summary>
        public Color[] SeriesColorsInit = 
        {
            Color.FromArgb(65, 140, 240),
            Color.FromArgb(224, 64, 10),
            Color.FromArgb(252, 180, 65),
            Color.FromArgb(5, 100, 146),
            Color.FromArgb(191, 191, 191),
            Color.FromArgb(26, 59, 105),
            Color.FromArgb(255, 227, 130),
            Color.FromArgb(18, 156, 221),
            Color.FromArgb(202, 107, 75),
            Color.FromArgb(0, 92, 219)
        };



        /// <summary>
        /// 系列(Series)颜色
        /// 修改:杨斌 2012-06-28
        /// </summary>
        public Color[] SeriesColors
        {
            get
            {
                //return seriesColors;
                Color[] aryColors = new Color[9999];
                int count = SeriesColorsInit.Length;
                for (int i = 0; i < aryColors.Length; i++)
                {
                    int n = i % count;
                    aryColors[i] = SeriesColorsInit[n];
                }
                return aryColors;
            }
            set
            {
                SeriesColorsInit = value;
                if (value == null || value.Length < 0)
                    throw (new ApplicationException("Series (Series) colors set at least one color"));
            }
        }
        /// <summary>
        /// Point颜色
        /// </summary>
        public Color[] PointColors { get; set; }

        //杨斌 2014-06-04。默认改为0
        private double pointWidth = 0;//必须设置,因为默认为0。图表控件应默认设置为1,否则默认为0时图表柱状图画不出来 2012-02-02
        /// <summary>
        /// 系列各项的宽度,必须0-1之间,0表示默认
        /// </summary>
        public double PointWidth
        {
            get
            {
                return pointWidth;
            }
            set
            {
                if (value < 0 || value > 1)
                    throw (new ApplicationException("The width of the series, must be between 0-1"));
                pointWidth = (value < 0 || value > 1) ? 1 : value;
            }
        }

        /// <summary>
        /// 是否显示图例
        /// </summary>
        private bool legendEnable = true;
        public bool LegendEnable
        {
            get
            {
                return legendEnable;
            }
            set
            {
                legendEnable = value;
            }
        }


        private LegendStyles legendStyle = LegendStyles.lsColumn;
        /// <summary>
        /// 图例样式
        /// </summary>
        private LegendStyles LegendStyle
        {
            get
            {
                return legendStyle;
            }
            set
            {
                legendStyle = value;
            }
        }

        private Font legendFont = new Font("Arial", 8);
        /// <summary>
        /// 图例文本格式,如字体、字号、字形属性
        /// </summary>
        private Font LegendFont
        {
            get
            {
                return legendFont;
            }
            set
            {
                legendFont = value;
            }
        }


        private LegentAlignments legendAlignment = LegentAlignments.laCenter;
        /// <summary>
        /// 图例对齐方式,默认居中对齐
        /// </summary>
        public LegentAlignments LegendAlignment
        {
            get
            {
                return legendAlignment;
            }
            set
            {
                legendAlignment = value;
            }
        }


        private LegentDockings legentDocking = LegentDockings.ldBottom;
        /// <summary>
        /// 图例位置
        /// </summary>
        public LegentDockings LegentDocking
        {
            get
            {
                return legentDocking;
            }
            set
            {
                legentDocking = value;
            }
        }

        private Color legentForeColor = Color.Black;
        /// <summary>
        /// 图例文本颜色
        /// </summary>
        public Color LegentForeColor
        {
            get
            {
                return legentForeColor;
            }
            set
            {
                legentForeColor = value;
            }
        }

        /// <summary>
        /// 图例文本
        /// </summary>
        public string[] LegentText { get; set; }


        /// <summary>
        /// 是否3D图
        /// </summary>
        private bool is3D = false;
        public bool Is3D
        {
            get
            {
                return is3D;
            }
            set
            {
                is3D = value;
            }
        }

        private bool axisYEnable = false;
        /// <summary>
        /// 是否显示Y轴,默认显示
        /// </summary>
        private bool AxisYEnabled
        {
            get
            {
                return axisYEnable;
            }
            set
            {
                axisYEnable = value;
            }
        }

        private bool axisXEnable = true;
        private int iChangeColor = 0;  //0:初始值,1:Bar图,2:Other图   20120204
        private int iChiceCount = 0;   //记录Bar图选项选项个数(Bar图时记录) 20120204

        /// <summary>
        /// 是否显示X轴,默认显示
        /// </summary>
        public bool AxisXEnabled
        {
            get
            {
                return axisXEnable;
            }
            set
            {
                axisXEnable = value;
            }
        }

        /// <summary>
        /// 柱状图的最大值
        /// </summary>
        private int maxValue = 0;
        public int MaxValue
        {
            get
            {
                return maxValue;
            }
            set
            {
                maxValue = value;
            }
        }

        private Font dataLabelFont = new Font("Arial", 14);
        /// <summary>
        /// 数据标签字体
        /// 创建:杨斌 2012-06-26
        /// </summary>
        public Font DataLabelFont
        {
            get { return dataLabelFont; }
            set { dataLabelFont = value; }
        }

        /// <summary>
        /// 是否使用系统字体
        /// 杨斌 2015-05-29
        /// </summary>
        public bool UseSystemFont = true;

        private Color dataLabelColor = Color.Black;
        /// <summary>
        /// 数据标签颜色
        /// 创建:杨斌 2012-06-26
        /// </summary>
        public Color DataLabelColor
        {
            get { return dataLabelColor; }
            set { dataLabelColor = value; }
        }

        private Font itemLabelFont = new Font("Arial", 16);
        /// <summary>
        /// 选项标签字体
        /// 创建:杨斌 2012-06-26
        /// </summary>
        public Font ItemLabelFont
        {
            get { return itemLabelFont; }
            set { itemLabelFont = value; }
        }

        private Color itemLabelColor = Color.Black;
        /// <summary>
        /// 选项标签颜色
        /// 创建:杨斌 2012-06-26
        /// </summary>
        public Color ItemLabelColor
        {
            get { return itemLabelColor; }
            set { itemLabelColor = value; }
        }

        /// <summary>
        /// 图表最大数据值,用于柱状图或条形图最大长度设置
        /// 若为0则长度自动适应
        /// 创建:杨斌 2013-02-21
        /// </summary>
        public double MaxDataValue = 0;

        /// <summary>
        /// 是否强制显示选项文本
        /// 杨斌 2015-01-08
        /// </summary>
        //public bool ShowItemText = false;

        /// <summary>
        /// 使用堆积图
        /// 杨斌 2014-11-04
        /// </summary>
        public bool UseStacked = false;

        /// <summary>
        /// 图表更新
        /// </summary>
        /// <returns>初始化成功:True,初始化失败:False</returns>
        public bool UpdateChart(bool multiChartAreas = false)
        {
            //图表、字体清晰度(锯齿)
            MsChart.AntiAliasing = AntiAliasingStyles.Graphics;

            //图表背景色
            MsChart.BackColor = Color.Transparent;

            //图表位置
            //MsChart.Location = new System.Drawing.Point(5, 10);
            MsChart.Location = new System.Drawing.Point(0, 0);
            //图表大小
            MsChart.Size = new System.Drawing.Size(this.width, this.height);

            //清除图表(区域)
            MsChart.ChartAreas.Clear();
            
            //创建图表区域
            ChartArea chartArea = new ChartArea();

            //ChartAreas:增加多个绘图区域,每个绘图区域包含独立的图表组、数据源,用于多个图表类型在一个绘图区不兼容时。

            //添加图表区域到图表
            MsChart.ChartAreas.Add(chartArea);
            MsChart.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//解决图表显示13 5 7 9 11问题

            //是否3D
            chartArea.Area3DStyle.Enable3D = this.is3D;//.ChartParam.Is3D;
            //设置图片旋转角度、倾斜角度
            if (this.chartType == ChartTypes.ctPie)
            {
                //旋转角度
                chartArea.Area3DStyle.Rotation = 0;
                //倾斜角度
                chartArea.Area3DStyle.Inclination = 25;  //20111226修改
            }
            else
            {
                //旋转角度
                chartArea.Area3DStyle.Rotation = 10;
                //倾斜角度
                chartArea.Area3DStyle.Inclination = 20;
            }

            //数据列是否聚合
            chartArea.Area3DStyle.IsClustered = false;// this.ChartParam.IsClustered;

            //图表区域背景色
            chartArea.BackColor = Color.Transparent;

            //是否显示Y轴
            chartArea.AxisY.Enabled = this.AxisYEnabled ? AxisEnabled.True : AxisEnabled.False;

            //是否显示x轴
            chartArea.AxisX.Enabled = axisXEnable ? AxisEnabled.True : AxisEnabled.False;

            //X/Y轴网格线
            chartArea.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
            chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;

            //X/Y轴标签文本格式,如字体、字号、字形属性(必须放在Add之后,否则字号无效)
            // chartArea.AxisX.LabelStyle.Font = new Font("Arial", 16); ;
            // chartArea.AxisY.LabelStyle.Font = new Font("Arial", 16); ;

            //X/Y轴标签文本颜色
            chartArea.AxisY.LabelStyle.ForeColor = Color.Black;
            chartArea.AxisX.LabelStyle.ForeColor = ItemLabelColor;//Color.Black;//杨斌 2012-06-26

            //系列各项深度,3D时有效,取值0-1000之间,默认60
            chartArea.Area3DStyle.PointDepth = 60;// this.ChartParam.PointDepth;

            //系列各项前后空白的深度,3D时有效,取值0-1000之间,默认100
            chartArea.Area3DStyle.PointGapDepth = 100;// this.ChartParam.PointGapDepth;

            this.MsChart.Series.Clear();
            if (iChangeColor == 1 && iChiceCount > 1)  // 颜色翻转-颜色还原 --解决由5个选项变成7个选项颜色会变的bug jdragon -2012-02-06
            {
                Color[] tempColors = this.SeriesColors;
                Color tempColor;
                for (int j = 0; j < iChiceCount / 2; j++)
                {
                    tempColor = tempColors[iChiceCount - 1 - j];
                    tempColors[iChiceCount - 1 - j] = tempColors[j];
                    tempColors[j] = tempColor;
                }
                this.SeriesColors = tempColors;
                iChangeColor = 2;
            }

            //如果是条形图,反转数据,颜色翻转 杨斌 2014-03-21
            if ((this.chartType == ChartTypes.ctBar) ||
                (this.chartType == ChartTypes.ctBarBox) ||
                (this.chartType == ChartTypes.ctText))//杨斌 2015-04-20
            {
                //杨斌 2014-12-09
                string tempXVal;
                double tempYVal;
                int count = XValue.Length;
                for (int j = 0; j < count / 2; j++)
                {
                    tempXVal = XValue[j];
                    XValue[j] = XValue[count - 1 - j];
                    XValue[count - 1 - j] = tempXVal;
                }
                for (int i = 0; i < YValues.Count; i++)
                {
                    count = YValues[i].Length;
                    for (int j = 0; j < count / 2; j++)
                    {
                        //tempXVal = XValue[j];
                        //XValue[j] = XValue[count - 1 - j];
                        //XValue[count - 1 - j] = tempXVal;

                        tempYVal = YValues[i][j];
                        YValues[i][j] = YValues[i][count - 1 - j];
                        YValues[i][count - 1 - j] = tempYVal;
                    }
                }
            }

            //找到最大数据值,方便设置柱状图最大高度。杨斌 2012-04-11
            double yValueMax = maxValue;
            //for (int i = 0; i < this.YValues.Count; i++)
            //{
            //    double[] YVals = this.YValues[i];
            //    for (int j = 0; j < YVals.Length; j++)
            //    {
            //        if (YVals[j] > yValueMax)
            //            yValueMax = YVals[j];
            //    }
            //}
            if (this.YValues.Count > 1)//杨斌 2014-11-04
            {
                if (UseStacked)
                {
                    for (int j = 0; j < this.YValues[0].Length; j++)
                    {
                        double count = 0;
                        for (int i = 0; i < this.YValues.Count; i++)
                        {
                            count += this.YValues[i][j];
                        }
                        if (count > yValueMax)
                            yValueMax = count;
                    }
                }
                else
                {
                    for (int i = 0; i < this.YValues.Count; i++)
                    {
                        double[] YVals = this.YValues[i];
                        for (int j = 0; j < YVals.Length; j++)
                        {
                            if (YVals[j] > yValueMax)
                                yValueMax = YVals[j];
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < this.YValues.Count; i++)
                {
                    double[] YVals = this.YValues[i];
                    for (int j = 0; j < YVals.Length; j++)
                    {
                        if (YVals[j] > yValueMax)
                            yValueMax = YVals[j];
                    }
                }
            }



            //创建数据系列
            for (int i = 0; i < this.YValues.Count; i++)
            {
                Series series = new Series();

                //DrawingStyle取值范围:Cylinder 、Emboss、LightToDark、Wedge、Default。杨斌 2014-04-18

                //图表类型
                switch (this.chartType)
                {

                    case ChartTypes.ctColumn:
                    case ChartTypes.ctColumnBox:
                        //series.ChartType = SeriesChartType.Column;
                        if ((this.YValues.Count > 1) && UseStacked)//杨斌 2014-11-04
                        {
                            series.ChartType = SeriesChartType.StackedColumn;
                            //this.LegendStyle = LegendStyles.lstTable;
                            this.LegendStyle = LegendStyles.lsColumn;
                        }
                        else
                        {
                            series.ChartType = SeriesChartType.Column;
                            this.LegendStyle = LegendStyles.lsColumn;
                        }
                        //系列效果 杨斌 2014-11-04
                        if (this.chartType == ChartTypes.ctColumn)
                            series["DrawingStyle"] = "Cylinder";       // 圆柱
                        else
                            series["DrawingStyle"] = "Default";

                        //if (iChangeColor == 1 && iChiceCount > 1)  // 颜色翻转(上次是Bar时颜色时翻转) -jdragon 20120204
                        //{
                        //    Color[] tempColors = this.SeriesColors;
                        //    Color tempColor;
                        //    for (int j = 0; j < iChiceCount / 2; j++)
                        //    {
                        //        tempColor = tempColors[iChiceCount - 1 - j];
                        //        tempColors[iChiceCount - 1 - j] = tempColors[j];
                        //        tempColors[j] = tempColor;
                        //    }
                        //    this.SeriesColors = tempColors;
                        //}
                        //iChangeColor = 2;
                        break;
                    case ChartTypes.ctBar:
                    case ChartTypes.ctBarBox:
                    case ChartTypes.ctText://杨斌 2015-04-20
                        //series.ChartType = SeriesChartType.Bar;
                        if ((this.YValues.Count > 1) && UseStacked)//杨斌 2014-11-04
                        {
                            series.ChartType = SeriesChartType.StackedBar;
                            //this.LegendStyle = LegendStyles.lstTable;
                            this.LegendStyle = LegendStyles.lsColumn;
                        }
                        else
                        {
                            series.ChartType = SeriesChartType.Bar;
                            this.LegendStyle = LegendStyles.lsColumn;
                        }
                        //系列效果 杨斌 2014-11-04
                        if (this.chartType == ChartTypes.ctBar)
                            series["DrawingStyle"] = "Cylinder";       // 圆柱
                        else
                            series["DrawingStyle"] = "Default";

                        ////颜色翻转--20120202
                        //string[] XValsTemp = this.XValue;
                        //if (iChangeColor != 1)  //颜色翻转
                        //{
                        //    Color[] tempColors = this.SeriesColors;
                        //    int count = XValsTemp.Length;
                        //    iChiceCount = XValsTemp.Length;
                        //    Color tempColor;
                        //    for (int j = 0; j < count / 2; j++)
                        //    {
                        //        tempColor = tempColors[count - 1 - j];
                        //        tempColors[count - 1 - j] = tempColors[j];
                        //        tempColors[j] = tempColor;
                        //    }
                        //    this.SeriesColors = tempColors;
                        //    iChangeColor = 1;
                        //}

                        break;
                    //case ChartTypes.ctColumnBox://杨斌 2014-04-22
                    //    series.ChartType = SeriesChartType.Column;
                    //    //系列效果
                    //    series["DrawingStyle"] = "Default";
                    //    break;
                    //case ChartTypes.ctBarBox://杨斌 2014-04-22
                    //    series.ChartType = SeriesChartType.Bar;
                    //    //系列效果
                    //    series["DrawingStyle"] = "Default";
                    //    break;
                    case ChartTypes.ctPie://PieDrawingStyle范围:Default、SoftEdge、Concave
                        series.ChartType = SeriesChartType.Pie;
                        //系列效果
                        series["PieDrawingStyle"] = "Default";//默认
                        //if (iChangeColor == 1 && iChiceCount > 1)   // 颜色翻转(上次是Bar时颜色时翻转) -jdragon 20120204
                        //{
                        //    Color[] tempColors = this.SeriesColors;
                        //    Color tempColor;
                        //    for (int j = 0; j < iChiceCount / 2; j++)
                        //    {
                        //        tempColor = tempColors[iChiceCount - 1 - j];
                        //        tempColors[iChiceCount - 1 - j] = tempColors[j];
                        //        tempColors[j] = tempColor;
                        //    }
                        //    this.SeriesColors = tempColors;
                        //}
                        //iChangeColor = 2;
                        break;
                }


                //屏蔽下面代码,反转数据放到前面。杨斌 2014-11-10
                ////绑定数据
                //string[] XVals = this.XValue;
                //double[] YVals = this.YValues[i];

                //if ((series.ChartType == SeriesChartType.Bar) ||
                //(series.ChartType == SeriesChartType.StackedBar) ||
                //(series.ChartType == SeriesChartType.StackedBar100))//如果是条形图,反转数据,颜色翻转 杨斌 2014-03-21
                //{
                //    string tempXVal;
                //    double tempYVal;
                //    int count = XVals.Length;
                //    for (int j = 0; j < count / 2; j++)
                //    {
                //        tempXVal = XVals[count - 1 - j];
                //        tempYVal = YVals[count - 1 - j];
                //        XVals[count - 1 - j] = XVals[j];
                //        YVals[count - 1 - j] = YVals[j];
                //        XVals[j] = tempXVal;
                //        YVals[j] = tempYVal;
                //    }
                //    //绑定数据
                //    series.Points.DataBindXY(XVals, YVals);
                //}
                //else
                //绑定数据                

                //不显示柱状图。杨斌 2015-04-20
                ////series.Points.DataBindXY(this.XValue, this.YValues[i]);
                double[] zeroVal = new double[this.YValues[i].Length];
                bool showBar = !(this.chartType == ChartTypes.ctText);
                if (showBar)
                    series.Points.DataBindXY(this.XValue, this.YValues[i]);
                else
                {
                    chartArea.AxisX.LineColor = Color.Transparent;
                    chartArea.AxisX.MajorTickMark.Enabled = false;
                    chartArea.AxisX.MajorGrid.Enabled = false;

                    series.Points.DataBindXY(this.XValue, zeroVal);
                }

                //设置标签
                series.IsValueShownAsLabel = true;

                switch (this.labelType)
                {
                    case LabelTypes.ltNone://不显示标签
                        series.IsValueShownAsLabel = false;
                        break;
                    case LabelTypes.ltNumberValue://显示数值
                        for (int j = 0; j < series.Points.Count; j++)
                        {
                            //if (NumberDec < 0)//杨斌 2014-08-07
                            //    series.Points[j].Label = series.Points[j].GetValueByName("Y").ToString();
                            //else
                            //    series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", series.Points[j].GetValueByName("Y"));

                            if (NumberDec < 0)//杨斌 2014-08-07
                                series.Points[j].Label = this.YValues[i][j].ToString();
                            else
                                series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", this.YValues[i][j]);
                        }
                        break;
                    case LabelTypes.ltPercent://显示百分比
                        for (int j = 0; j < series.Points.Count; j++)
                        {
                            if (this.LabelDenominator > 0)//设置了分母
                            {
                                //series.Points[j].Label = String.Format("{0:F" + PercentDec.ToString() + "}", series.Points[j].GetValueByName("Y") / this.LabelDenominator * 100) + "%";
                                series.Points[j].Label = String.Format("{0:F" + PercentDec.ToString() + "}", this.YValues[i][j] / this.LabelDenominator * 100) + "%";
                            }
                            else if (this.LabelDenominator == 0)//没有设置分母
                            {
                                double count = this.SumPointsValue(series);
                                if (this.UseStacked)//杨斌 2014-11-10
                                {
                                    count = 0;
                                    for (int n = 0; n < YValues.Count; n++)
                                        count += YValues[n][j];
                                }
                                //杨斌 2015-06-18
                                if ((this.LabelDenominatorOptionLimit == 0) || (j < this.LabelDenominatorOptionLimit))
                                    //series.Points[j].Label = String.Format("{0:F" + PercentDec.ToString() + "}", (count > 0 ? series.Points[j].GetValueByName("Y") / count : 0) * 100) + "%";
                                    series.Points[j].Label = String.Format("{0:F" + PercentDec.ToString() + "}", (count > 0 ? this.YValues[i][j] / count : 0) * 100) + "%";
                                else
                                    series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", this.YValues[i][j]);

                            }
                        }
                        break;
                    case LabelTypes.ltNumberValueAndPercent://显示数值加百分比
                        for (int j = 0; j < series.Points.Count; j++)
                        {
                            if (this.LabelDenominator > 0)//设置了分母
                            {
                                if (series.ChartType == SeriesChartType.Bar)
                                {
                                    //series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", series.Points[j].GetValueByName("Y")) + ";  " +
                                    //  String.Format("{0:F" + PercentDec.ToString() + "}", series.Points[j].GetValueByName("Y") / this.LabelDenominator * 100) + "%";
                                    series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", this.YValues[i][j]) + ";  " +
                                      String.Format("{0:F" + PercentDec.ToString() + "}", this.YValues[i][j] / this.LabelDenominator * 100) + "%";
                                }
                                else
                                {
                                    //series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", series.Points[j].GetValueByName("Y")) + "\n" +
                                    //    String.Format("{0:F" + PercentDec.ToString() + "}", series.Points[j].GetValueByName("Y") / this.LabelDenominator * 100) + "%";
                                    series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", this.YValues[i][j]) + "\n" +
                                        String.Format("{0:F" + PercentDec.ToString() + "}", this.YValues[i][j] / this.LabelDenominator * 100) + "%";
                                }
                            }
                            else if (this.LabelDenominator == 0)//没有设置分母
                            {
                                double count = this.SumPointsValue(series);
                                if (this.UseStacked)//杨斌 2014-11-10
                                {
                                    count = 0;
                                    for (int n = 0; n < YValues.Count; n++)
                                        count += YValues[n][j];
                                }
                                //杨斌 2015-06-18
                                string spl = "; ";
                                if (series.ChartType == SeriesChartType.Bar)
                                {
                                    spl = "; ";
                                }
                                else
                                {
                                    spl = "\n";
                                }
                                series.Points[j].Label = String.Format("{0:F" + NumberDec.ToString() + "}", this.YValues[i][j]);
                                if ((this.LabelDenominatorOptionLimit == 0) || (j < this.LabelDenominatorOptionLimit))
                                    series.Points[j].Label += spl + String.Format("{0:F" + PercentDec.ToString() + "}", (count > 0 ? this.YValues[i][j] / count : 0) * 100) + "%";

                            }

                        }

                        break;
                }

                //杨斌 2014-09-01 3D条形图数据标签右移
                if (this.labelType != LabelTypes.ltNone)
                {
                    if (chartArea.Area3DStyle.Enable3D)
                    {
                        switch (series.ChartType)
                        {
                            case SeriesChartType.Bar:
                                for (int j = 0; j < series.Points.Count; j++)
                                {
                                    series.Points[j].Label = "  " + series.Points[j].Label;
                                }
                                break;
                        }
                    }
                }

                if (this.labelType != LabelTypes.ltNone)
                {
                    //堆积图表数据为0不显示。杨斌 2014-02-20
                    for (int j = 0; j < series.Points.Count; j++)
                    {
                        switch (series.ChartType)
                        {
                            case SeriesChartType.StackedColumn:
                            case SeriesChartType.StackedBar:
                                if (series.Points[j].GetValueByName("Y") == 0)
                                    series.Points[j].Label = " ";
                                //series.Label = "AA";
                                break;
                        }
                    }
                }

                if ((this.YValues.Count > 1) && UseStacked)//杨斌 2014-01-27
                {
                }
                else
                {
                    //控制百分比显示在柱状图的外面,杨斌 2012-04-11
                    //chartArea.AxisY.Maximum = yValueMax * 1.16;// Double.NaN;//默认自动
                    //if (hchuw < 0.9) hchuw = 0.9;
                    //switch (this.labelType)
                    //{
                    //    case LabelTypes.ltNone://不显示标签       
                    //        break;
                    //    case LabelTypes.ltNumberValue://显示数值
                    //        break;
                    //    case LabelTypes.ltPercent://显示百分比
                    //        if (this.ChartType == ChartTypes.ctBar)
                    //            chartArea.AxisY.Maximum = yValueMax * 1.4;
                    //        break;
                    //    case LabelTypes.ltNumberValueAndPercent://显示数值加百分比
                    //        if (this.ChartType == ChartTypes.ctBar)
                    //            chartArea.AxisY.Maximum = yValueMax * 1.7;
                    //        break;
                    //}
                    //杨斌 2012-06-06
                    chartArea.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.WordWrap;

                    double wchuh = (double)MsChart.Width / MsChart.Height;
                    if (wchuh > 2)
                        chartArea.AxisY.Maximum = yValueMax + 25;
                    else
                        chartArea.AxisY.Maximum = yValueMax * 2 + 30;

                    //杨斌 2013-02-22
                    if (MaxDataValue > yValueMax)
                        yValueMax = MaxDataValue;
                    double cC = 0;//字宽/高
                    double cL = 0;//柱宽/高
                    switch (this.chartType)
                    {
                        case ChartTypes.ctBar:
                        case ChartTypes.ctBarBox://杨斌 2014-04-22
                            cC = 15 * dataLabelFont.Size / 14;//字宽。字号14,16=15,根据字体算
                            cL = (double)MsChart.Width * 0.9;//柱宽  
                            switch (this.labelType)
                            {
                                case LabelTypes.ltNone://不显示标签       
                                    break;
                                case LabelTypes.ltNumberValue://显示数值
                                    cC *= (((int)yValueMax).ToString().Length + 1);
                                    break;
                                case LabelTypes.ltPercent://显示百分比
                                    cC *= ("100.0%".Length);
                                    //cC *= 0.95;//杨斌 2013-03-14
                                    break;
                                case LabelTypes.ltNumberValueAndPercent://显示数值加百分比
                                    cC *= (((int)yValueMax).ToString().Length + "; 100.0%".Length);
                                    //cC *= 0.95;//杨斌 2013-03-14
                                    break;
                            }
                            if (cL > cC)
                            {
                                double cL2 = cL - cC;//去掉字宽的条形图柱宽
                                yValueMax = yValueMax * cL / cL2;
                            }
                            else
                            {
                                yValueMax = yValueMax * 100;
                            }
                            break;
                        case ChartTypes.ctColumn:
                        case ChartTypes.ctColumnBox://杨斌 2014-04-22
                            cC = 30 * dataLabelFont.Size / 14;//字高。字号14,16=30,根据字体算
                            cL = (double)MsChart.Height * 0.8;//柱高  

                            //杨斌 2015-03-31
                            if ((chartArea.AxisX.Enabled == AxisEnabled.True) && (XValue.Length > 0))
                            {
                                foreach (string s in XValue)
                                {
                                    if (Encoding.Default.GetByteCount(s) > 10)
                                    {
                                        cL = cL * 0.5;
                                        break;
                                    }
                                }
                            }

                            switch (this.labelType)
                            {
                                case LabelTypes.ltNone://不显示标签       
                                    break;
                                case LabelTypes.ltNumberValue://显示数值                                
                                    break;
                                case LabelTypes.ltPercent://显示百分比                                
                                    break;
                                case LabelTypes.ltNumberValueAndPercent://显示数值加百分比
                                    cC *= 2;//两行显示
                                    break;
                            }
                            if (cL > cC)
                            {
                                double cL2 = cL - cC;//去掉字宽的条形图柱宽
                                yValueMax = yValueMax * cL / cL2;
                            }
                            else
                            {
                                yValueMax = yValueMax * 100;
                            }
                            break;
                    }
                }
                chartArea.AxisY.Maximum = yValueMax;

                //系列颜色
                series.Color = this.SeriesColors[i % this.SeriesColors.Length];

                //杨斌 2012-06-26
                ////系列标签文本格式
                ////series.Font = new Font("Arial", 16);                 
                //if (series.Points.Count > 16)
                //{
                //    series.Font = new Font("Arial", 4);
                //    chartArea.AxisX.LabelStyle.Font = new Font("Arial", 4);
                //    chartArea.AxisY.LabelStyle.Font = new Font("Arial", 4);
                //}
                //else
                //{
                //    float size = 16;//原来是20 杨斌 2012-06-06
                //    series.Font = new Font("Arial", size - series.Points.Count);
                //    //X/Y轴标签文本格式,如字体、字号、字形属性(必须放在Add之后,否则字号无效)
                //    chartArea.AxisX.LabelStyle.Font = new Font("Arial", size - series.Points.Count);
                //    chartArea.AxisY.LabelStyle.Font = new Font("Arial", size - series.Points.Count);
                //}

                //杨斌 2015-05-29
                if (this.UseSystemFont)
                {
                    chartArea.AxisX.LabelStyle.Font = new Font(GlobalInfo.SysFontName, ItemLabelFont.Size);// new Font("Arial", 16);//杨斌 2012-06-26
                    chartArea.AxisY.LabelStyle.Font = new Font(GlobalInfo.SysFontName, 16);
                    series.Font = new Font(GlobalInfo.SysFontName, DataLabelFont.Size);// new Font("Arial", 16);//杨斌 2012-06-26
                }
                else
                {
                    chartArea.AxisX.LabelStyle.Font = ItemLabelFont;// new Font("Arial", 16);//杨斌 2012-06-26
                    chartArea.AxisY.LabelStyle.Font = new Font("Arial", 16);
                    series.Font = DataLabelFont;// new Font("Arial", 16);//杨斌 2012-06-26
                }

                //系列标签文本颜色
                series.LabelForeColor = DataLabelColor;// Color.Black;//杨斌 2012-06-26

                //添加数据系列
                this.MsChart.Series.Add(series);

                //如果是饼图设置Point边框
                if (this.is3D == false && this.chartType == ChartTypes.ctPie)
                {
                    for (int j = 0; j < series.Points.Count; j++)
                    {
                        series.Points[j].BorderColor = Color.Silver;
                        series.Points[j].BorderDashStyle = ChartDashStyle.Solid;
                        series.Points[j].BorderWidth = 1;
                    }
                }

            }

            //设置图表区域大小,尽量大。杨斌 2012-04-11
            for (int i = 0; i < MsChart.ChartAreas.Count; i++)
            {
                //MsChart.ChartAreas[i].Position.Width = 100;
                //MsChart.ChartAreas[i].Position.Height = 100;
            }

            //设置Point颜色,只支持一个系列时设置
            if (MsChart.Series.Count == 1)
            {
                if ((this.chartType == ChartTypes.ctBar) || (this.chartType == ChartTypes.ctBarBox))//颜色翻转 杨斌 2014-04-22
                {
                    if (this.PointColors != null && this.PointColors.Length > 0)
                    {
                        for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                            MsChart.Series[0].Points[j].Color = this.PointColors[(this.PointColors.Length - 1 - j) % this.PointColors.Length];
                    }
                    else
                    {
                        for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                            MsChart.Series[0].Points[j].Color = this.SeriesColors[(MsChart.Series[0].Points.Count - 1 - j) % MsChart.Series[0].Points.Count];
                    }
                }
                else
                {
                    if (this.PointColors != null && this.PointColors.Length > 0)
                    {
                        for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                            MsChart.Series[0].Points[j].Color = this.PointColors[j % this.PointColors.Length];
                    }
                    else
                    {
                        for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                        {
                            MsChart.Series[0].Points[j].Color = this.SeriesColors[j % MsChart.Series[0].Points.Count];
                        }
                    }
                }
                //if (this.PointColors != null && this.PointColors.Length > 0)
                //{
                //    for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                //        MsChart.Series[0].Points[j].Color = this.PointColors[j % this.PointColors.Length];
                //}
                //else
                //{
                //    for (int j = 0; j < MsChart.Series[0].Points.Count; j++)
                //        MsChart.Series[0].Points[j].Color = this.SeriesColors[j % MsChart.Series[0].Points.Count];
                //}
            }


            //系列各项的宽度,必须0-1之间,0表示默认
            for (int i = 0; i < MsChart.Series.Count; i++)
            {
                string pointWidth = "";
                if (this.PointWidth == 0)//杨斌 2014-05-14
                    pointWidth = (Double.Parse(MsChart.Series.Count.ToString()) / (MsChart.Series.Count + 1)).ToString();
                else
                    pointWidth = this.PointWidth.ToString();
                pointWidth = pointWidth.Replace(',', '.');
                MsChart.Series[i]["PointWidth"] = pointWidth;
                //MsChart.Series[i]["PointWidth"] = "0.1";
                MsChart.Series[i]["PieStartAngle"] = "270";//饼图起始角度 杨斌 2012-06-08

                //饼图变形。杨斌 2015-07-07
                //MsChart.Series[i].Points[0].BorderWidth = 3;
                //MsChart.Series[i].Points[1].BorderWidth = 100;
            }

            //杨斌 2015-02-10
            chartArea.AxisX.IsLabelAutoFit = true;
            chartArea.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30;
            //chartArea.AxisX.LabelStyle.Angle = 45;//-90到90之间

            MsChart.Legends.Clear();
            //图例设置  && (this.chartType ==ChartTypes.ctPie)
            if (this.legendEnable)
            {
                MsChart.Legends.Add("");
                //背景透明
                MsChart.Legends[0].BackColor = Color.Transparent;
                //图例位置
                MsChart.Legends[0].Docking = (Docking)((int)this.legentDocking);
                //图例样式
                MsChart.Legends[0].LegendStyle = (LegendStyle)((int)this.LegendStyle);
                //图例对齐方式
                MsChart.Legends[0].Alignment = (StringAlignment)((int)this.LegendAlignment);

                //图例标签文本格式。系统字体。杨斌 2015-05-29
                if (this.UseSystemFont)
                    MsChart.Legends[0].Font = new Font(GlobalInfo.SysFontName, chartArea.AxisX.LabelStyle.Font.Size);// this.legendFont;//杨斌 2012-06-26
                else
                    MsChart.Legends[0].Font = chartArea.AxisX.LabelStyle.Font;// this.legendFont;//杨斌 2012-06-26

                //图例文本颜色
                MsChart.Legends[0].ForeColor = chartArea.AxisX.LabelStyle.ForeColor;// this.LegentForeColor;//杨斌 2012-06-26

                //图例文本
                if (this.LegentText != null)
                {
                    if (this.ChartType == ChartTypes.ctPie)//如果是饼图
                    {
                        for (int i = 0; i < MsChart.Series.Count; i++)
                        {
                            if (this.LegentText.Length >= MsChart.Series[i].Points.Count)
                            {
                                for (int j = 0; j < MsChart.Series[i].Points.Count; j++)
                                {
                                    MsChart.Series[i].Points[j].LegendText = this.LegentText[j];
                                }
                            }
                            else
                            {
                                throw (new ApplicationException("Legend text's number is not less than the number"));
                            }
                        }
                    }
                    else//如果是条形图或柱状图
                    {
                        if (this.LegentText.Length >= MsChart.Series.Count)
                        {
                            for (int i = 0; i < MsChart.Series.Count; i++)
                                MsChart.Series[i].Name = this.LegentText[i];
                        }
                        else
                        {
                            throw (new ApplicationException("Legend text's number is not less than the number"));
                        }
                    }
                }                
            }

            ////杨斌 2016-05-10
            //MsChart.Titles.Add(new Title("1    2    3", Docking.Left));
            //MsChart.Titles[MsChart.Titles.Count -1].TextOrientation = TextOrientation.Stacked;
            //MsChart.Titles[MsChart.Titles.Count - 1].Font = DataLabelFont;

            return true;
        }


        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="strPath">保存图片路径</param>
        /// <returns></returns>
        public bool SaveAsPicture(string strPath, string strPicName)
        {
            if (!System.IO.Directory.Exists(strPath))
            {
                // 目录不存在,建立目录 
                System.IO.Directory.CreateDirectory(strPath);
            }
            this.MsChart.SaveImage(strPath + strPicName, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Png);
            return true;
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public bool DeletePicture(string strPath)
        {
            File.Delete(strPath);
            return true;
        }

        /// <summary>
        /// 获取图表的图像
        /// 创建:杨斌 2012-02-07
        /// </summary>
        /// <returns></returns>
        public Bitmap GetBitmap()
        {
            int w = MsChart.Size.Width;
            int h = MsChart.Size.Height;
            Bitmap bm = new Bitmap(w, h);
            MsChart.DrawToBitmap(bm, new Rectangle(0, 0, w, h));
            return bm;
        }
    }
}