www.pudn.com > ingawiantscohesion.rar > Form1.cs, change:,size:2580b


using DevExpress.XtraCharts; 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
 
namespace ChartEmpty 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            #region 代码设置第一个图例使用右边的Y坐标(已在设计中配置,代码注释) 
            //SecondaryAxisY y2 = ((XYDiagram)chartControl1.Diagram).SecondaryAxesY[0]; 
            //((LineSeriesView)chartControl1.Series[0].View).AxisY = y2; 
            #endregion 
 
            //数据集 
            List<SeriesPoint> pointList1 = new List<SeriesPoint>(); 
            //List<SeriesPoint> pointList2 = new List<SeriesPoint>(); 
            DateTime now = DateTime.Now; 
            #region 模拟数据 
            for (int i = 0; i < 20; i++) 
            { 
                //x轴值 
                DateTime x = now.AddDays(i); 
                if (i % 5 == 0) 
                    pointList1.Add(new SeriesPoint(x, 18 * i + 2)); 
                else 
                    pointList1.Add(new SeriesPoint(x, 16 * i - 5)); 
            } 
            #endregion 
            //给图例赋值 
            chartControl1.Series[0].Points.AddRange(pointList1.ToArray()); 
            chartControl1.Series[1].Points.AddRange(pointList1.ToArray()); 
        } 
 
        #region 创建图表的第二坐标系(可创建n个,设计中已配置,此处只提供方法) 
        /// <summary> 
        /// 创建图表的第二坐标系 
        /// </summary> 
        /// <param name="series">Series对象</param> 
        /// <returns></returns> 
        private SecondaryAxisY CreateAxisY(Series series) 
        { 
            SecondaryAxisY myAxis = new SecondaryAxisY(series.Name); 
            ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxis); 
            ((LineSeriesView)series.View).AxisY = myAxis; 
            myAxis.Title.Text = series.Name; 
            myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐 
            myAxis.Title.Font = new Font("宋体", 9.0f); 
            Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致 
            myAxis.Title.TextColor = color; 
            myAxis.Label.TextColor = color; 
            myAxis.Color = color; 
            return myAxis; 
        } 
        #endregion 
 
    } 
 
}