首页 > 代码库 > [DevExpress]ChartControl之创建X,Y轴Title示例

[DevExpress]ChartControl之创建X,Y轴Title示例

关键代码:

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

<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>代码使用:

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

<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>运行效果:

image

希望有所帮助!谢谢!微笑

[DevExpress]ChartControl之创建X,Y轴Title示例