ucEquipTimePie.cs 3.79 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;//微软MSChart的定义空间

using MyClassLib;


namespace MyControlLib
{
    public partial class ucEquipTimePie : UserControl
    {
        public ucEquipTimePie()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 设定颜色
        /// </summary>
        public List<Color> color = new List<Color> { Color.Green,Color.SteelBlue,Color.Yellow,Color.Red,Color.Salmon,Color.RoyalBlue,Color.SpringGreen };

        public void DrawTimePie(string title,List<double>val,List<string> strTip)
        {
            //清除所有的数据
            //chart1.Series["Serial1"].
            //数值显示百分比形式
            //chart1.Series["Series1"].Label = "#PERCENT{P}";

            //chart1.Series["Series1"].ToolTip = "#LEGENDTEXT: #VAL{D} Min";
            Title tl = new Title(title);
            chart1.Titles.Clear();
            chart1.Titles.Add(tl);
            chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            chart1.Series["Series1"].LegendToolTip = "#PERCENT";
            //chart1.Series["Series1"].LegendText = "#PERCENT";
            //chart1.Series["Series1"].PostBackValue = "#INDEX";
            //chart1.Series["Series1"].LegendPostBackValue = "#INDEX";
            //chart1.Series["Series1"].
            
            chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle;  //设置点标记样式(此为圆点)
            chart1.Series["Series1"].MarkerColor = Color.White;
           // chart1.Series["Series1"].BorderColor = Color.Red;
            chart1.Series["Series1"].BorderWidth = 1;
            chart1.Series["Series1"].MarkerSize = 5;    //设置线节点大小

            //chart1.Series["Series1"].Points.DataBindXY(strTip, val);
            chart1.Series["Series1"].Points.DataBindXY(strTip.ToArray(),val.ToArray());
            int i = 0;
            foreach (var p in chart1.Series[0].Points)
            {
                p.Color = color[i++];
                if (i >= color.Count)
                {
                    i = 0;
                }
            }
            chart1.Series["Series1"].LabelToolTip = "#PERCENT{P}";
            chart1.Series["Series1"].ToolTip = "#PERCENT #VAL min";
            //chart1.Series["Series1"].ToolTip = "文章数#VAL"; //#VAL--Y轴数组
            
        }

        public void DrawTimePie( string title,string[] strTip,double[] val)
        {

            Title tl = new Title(title);
            chart1.Titles.Clear();
            chart1.Titles.Add(tl);
            chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            chart1.Series["Series1"].LegendToolTip = "#PERCENT";
            //chart1.Series["Series1"].LegendText = "#PERCENT";
            //chart1.Series["Series1"].PostBackValue = "#INDEX";
            //chart1.Series["Series1"].LegendPostBackValue = "#INDEX";
            //chart1.Series["Series1"].
            chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle;  //设置点标记样式(此为圆点)
            chart1.Series["Series1"].MarkerColor = Color.White;
            // chart1.Series["Series1"].BorderColor = Color.Red;
            chart1.Series["Series1"].BorderWidth = 1;
            chart1.Series["Series1"].MarkerSize = 5;    //设置线节点大小

            //chart1.Series["Series1"].Points.DataBindXY(strTip, val);
            chart1.Series["Series1"].Points.DataBindXY(strTip, val);
            chart1.Series["Series1"].ToolTip = "#PERCENT #VAL min";
            //chart1.Series["Series1"].ToolTip = "文章数#VAL"; //#VAL--Y轴数组
            
            
        }

    }
}