chartControl

关键代码:

        /// <summary>
        /// 设置X轴Title
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="titleText">Title文字</param>
        /// <param name="titleColor">Title文字颜色</param>
        public static void SetAxisXTitle(this ChartControl chart, string titleText, Color titleColor)
        {
            XYDiagram _diagram = (XYDiagram)chart.Diagram;
            if (_diagram != null)
            {
                _diagram.AxisX.Title.Visible = true;
                _diagram.AxisX.Title.Alignment = StringAlignment.Center;
                _diagram.AxisX.Title.Text = titleText;
                _diagram.AxisX.Title.TextColor = titleColor;
                _diagram.AxisX.Title.Antialiasing = true;
                _diagram.AxisX.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
            }
        }
        /// <summary>
        /// 设置Y轴Title
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="titleText">Title文字</param>
        /// <param name="titleColor">Title文字颜色</param>
        public static void SetAxisYTitle(this ChartControl chart, string titleText, Color titleColor)
        {
            XYDiagram _diagram = (XYDiagram)chart.Diagram;
            if (_diagram != null)
            {
                _diagram.AxisY.Title.Visible = true;
                _diagram.AxisY.Title.Alignment = StringAlignment.Center;
                _diagram.AxisY.Title.Text = titleText;
                _diagram.AxisY.Title.TextColor = titleColor;
                _diagram.AxisY.Title.Antialiasing = true;
                _diagram.AxisY.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
            }
        }

代码使用:

            chartControl1.SetAxisXTitle("时间x轴演示", Color.Red);
            chartControl1.SetAxisYTitle("时间y轴演示", Color.Red);

运行效果:

image

posted on 2015-01-15 18:24  zrSoldier  阅读(203)  评论(0编辑  收藏  举报